这段代码可以在VS2013正确运行,并且输出:
你好,133
你好,233
,但在代码::块(使用GCC编译器和在一个Ubuntu系统),编译器告诉我:嵌套℃的情况下++模板
|| ===构建:调试test_sth(编译器:GNU GCC编译器)=== |
在成员函数'void A :: say()'中:
line 28错误:''''令牌之前的预期主表达式
在'void A :: say()[with C = B]'的实例化中' :
线31从这里需要
第28行错误:类型的无效操作数“<悬而未决重载的函数类型>”和“INT”为二进制“运算符<”
|| ===建立失败:2错误(S ),2次警告(0分钟,0秒)=== |
有没有人可以告诉我什么是错的,为什么?
第28行是:this-> c.Match < 233>();
第31行是:模板结构A < B < int>>;
#include "stdio.h"
using namespace std;
template<typename C>
struct A
{
C c;
void say();
};
template<typename C>
class B
{
C name;
public:
template<int D>
void Match()
{
printf("hello,%d\n",D);
}
};
template<typename C>
void A<C>::say()
{
this->c.Match<233>();
}
template struct A<B<int>>;
int main()
{
A<B<int>> a1;
a1.c.Match<133>();
a1.say();
getchar();
return 0;
}
'这个 - > c.template匹配<233>();' – cpplearner