提取模板参数的值
Extracting template arguments' value
我有这个类:
#include <iostream>
template<typename T, typename... TT>
class List
{
public:
typedef T head;
typedef List<TT...> next;
enum { size = sizeof...(TT)+1 };
};
而这个主要:
#include <iostream>
#include "List.h"
using namespace std;
template <int T>
struct Int {
enum { value = T };
};
int main() {
typedef List<Int<1>, Int<2>, Int<3>> list;
cout << list::template head.value << endl; // Error
cout << list::size; // Works
return 0;
}
错误信息:
error: expected primary-expression before '.' token
cout << list::template head.value << endl;
我将不胜感激任何帮助..在过去的半个小时里,我一直在试图解决这个问题,这可能是一件非常愚蠢的事情,我只是无法说清楚。
head
是一种类型。这意味着你不能用template
消除它的歧义,也不能用.
访问它。修复它没有太多可做的:
std::cout << list::head::value << std::endl;
另外,请摆脱using namespace std;
。
相关文章:
- 将不同类型的模板参数包提取到双精度向量中会产生警告
- 如何提取模板参数中传递的类型
- C/C++预处理器:提取每秒的可变参数
- C++ 模板提取布尔参数
- 从模板参数的模板参数中提取值
- 使用C++元编程提取 C 函数的参数("Practical C++ Metaprogramming" 中的示例)
- 如何定义变体<x,y,z>提取模板参数的子类型
- 使用命令行参数从TXT文件中提取并在C 中运行特定类
- 为什么我只从可变参数模板中提取一个值?
- 提取模板参数的值
- C++从函数签名中提取参数
- 每个新客户端的 GStreamer 和 URI 查询参数提取
- 从文件名中提取文件名,路径来自参数
- 从参数包中提取成员类型
- 是否保证标准提取运算符>>在失败时不会更改参数?
- 从boost ::函数中提取参数
- 从结构中提取指针参数
- 如何实现递归"using"/提取模板参数
- 制作解析器以提取函数名称、参数、返回类型
- 从net.connman.Manager的GetService方法动态提取D-Bus参数和对象路径