Raj
Raj

Reputation: 273

passing reference of a variable to a template

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

Answers (1)

Xiaotian Pei
Xiaotian Pei

Reputation: 3260

Test<A.x> test; should be Test<A::x> test;

Upvotes: 3

Related Questions