使用模板对象的模板函数中无法识别的内容
Something unrecognize in template function working with a template object
Gcc (4.7.2) 在编译此代码时抛出一个小错误:
#include <iostream>
template<typename T>
struct test
{
template<int n>
int select() const
{
return n;
}
};
template<typename T>
struct test_wrapper
{
void print() const
{
std::cout << t.select<3>() << std::endl; // L.18
}
test<T> t;
};
int main()
{}
错误是:
test3.cpp: In member function 'void test_wrapper<T>::print() const':
test3.cpp:18:34: error: expected primary-expression before ')' token
如果我通过专用类型更改test<T> t
,例如test<void> t
,此错误会消失。
问题出在哪里?
在
模板化构造中调用模板方法时,需要使用 template
关键字:
t.template select<3>();
相关文章:
- 从不同的附加依赖项中识别等同命名的函数
- 静态堆栈函数不会 1) 输入第一个元素 2)添加新元素时识别旧元素
- 无法识别的类函数副本
- 函数无法识别我在C++传递节点指针向量?
- 如何识别符号表中的符号是我'application'函数
- C++ 编译错误:gnu_printf是无法识别的格式函数类型
- 函数的函数无法识别输入参数
- c++为什么ifstream get()函数返回无法识别的特殊字符
- 已定义构造函数的构造函数无法识别
- 模板函数无法识别
- C ++中的函数为什么我的编译器无法识别错误()
- 如何在 unordered_map 中使用 cpp 来识别 lambda 函数?
- 编写模式识别'函数以查找特定顺序出现的数字?C++
- 试图使用int []作为打字模板,编译器未识别函数最小的原型中的参数
- 表达式无法识别函数c++中的指针
- 引脚二进制检测:如何精确识别函数名称
- 无法识别函数定义
- 如何从头文件中快速识别函数
- AST 访问者函数调用表达式无法正确识别函数调用
- QML不能识别c++函数