<分区>
这段代码在VS2013中可以正常运行,输出:
你好,133
你好,233
,但是在 code::blocks(使用 GCC 编译器和 Ubuntu 系统)中,编译器告诉我:
||=== 构建:在 test_sth 中调试(编译器:GNU GCC 编译器)===|
在成员函数‘void A::say()’中:
第 28 行错误:')' 标记之前的预期主表达式
在“void A::say() [with C = B]”的实例化中:
此处需要第 31 行
第 28 行错误:类型为“<未解析的重载函数类型>”和“int”的无效操作数为二进制“operator<”
||=== 构建失败:2 个错误,2 个警告(0 分钟,0 秒)===|
有没有人能告诉我哪里出了问题,为什么?
第 28 行是:this->c.Match<233>();
第 31 行是:template struct 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;
}