gpt4 book ai didi

c++ - 模板元编程 : print type list

转载 作者:行者123 更新时间:2023-11-30 03:52:12 27 4
gpt4 key购买 nike

<分区>

如何打印类型列表??

这是我尝试过的 + 我的类型列表:

template<typename ...T>
struct typeList;
template<typename H, typename ...T>
struct typeList<H, T...> {
using head = H;
using tail = typeList<T...>;
public:
static inline void print(){
std::cout << H::name << " "; // How can I get the name of H ???
typeList<T...>::print();
}
};

template<>
struct typeList<>{
static inline void print(){
std::cout << endl;
}
};

所以typeList<A,B,C,int>::print()会给 A b C int ,

A B 和 C 是一些用户定义的结构

我可以在不添加名为 name 的静态函数的情况下执行此操作吗?在每个结构中??没有返回类型名称的编译时函数?

编辑:

这不是 this 的拷贝,我在哪里提到变量??

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com