Reputation: 273
I am trying to pass reference variable to a template with below code but I'm getting compiler error. Can any one figure out the reason please. Thanks.
#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;
}
Error:
error C2143: syntax error : missing ',' before '.'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
fatal error C1004: unexpected end-of-file found
Upvotes: 0
Views: 65