【发布时间】:2016-02-16 21:15:08
【问题描述】:
我正在尝试使用以下代码将引用变量传递给模板,但出现编译器错误。请问哪位大神能说说原因。谢谢。
#include<iostream>
using namespace std;
template<int &T>
class Test
{
public:
static void do_it()
{
T=1;
}
};
struct A{
static int x;
};
int A::x=0;
int main()
{
Test<A::x> test;
test.do_it();
cout<<A::x;
return 0;
}
错误:
错误 C2143:语法错误:在 '.' 之前缺少 ','
错误 C2143:语法错误:缺少“;”在'}'之前
错误 C2143:语法错误:缺少“;”在'}'之前
致命错误 C1004:发现意外的文件结尾
【问题讨论】: