小编Joo*_*Joo的帖子

在模板函数中打印任何结构

我有 3 个或更多 struct ,我希望我有一个函数来打印任何结构

例如 :

struct A 
{
  int a0;
  string a1;
  bool a2;
}
Run Code Online (Sandbox Code Playgroud)

struct B
{
 CString b0;
 double b1;
 int b2;
 string b3
}
Run Code Online (Sandbox Code Playgroud)

我想用相同的功能打印这个结构(A 和 B)

像这样 :

template<typename T>
inline void print(T)
{
  std::cout << // I don't know what is write here....
}
Run Code Online (Sandbox Code Playgroud)

任何机构帮助我?

c++ templates struct

4
推荐指数
1
解决办法
1403
查看次数

标签 统计

c++ ×1

struct ×1

templates ×1