Why this does not compile?

  • Thread starter Marcin Kalicinski
  • Start date
M

Marcin Kalicinski

Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".

cheers,
Marcin
 
A

Andrey Tarasevich

Marcin said:
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".
...

Template members of dependent types have to be referred to with the explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}
 
M

Marcin Kalicinski

Template members of dependent types have to be referred to with the
explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}


Thanks, that was quick!

Best regards,
Marcin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top