Use of template keyword in callsite

D

Dilip

Warning: Newbie clueless question.

I ran into something at work today that I solved by random hackery
without really understanding it. Can someone explain to me why the
template keyword is required at the callsite of this static template
function?

class foo
{
public:
template<typename T>
static void dosomethingtoT(T& value)
{
value = 44;
}
};

int main()
{
long l;
foo::template dosomethingtoT(l); // why the template keyword??
return 0;
}
 
A

Alf P. Steinbach

* Dilip:
Warning: Newbie clueless question.

I ran into something at work today that I solved by random hackery
without really understanding it. Can someone explain to me why the
template keyword is required at the callsite of this static template
function?

class foo
{
public:
template<typename T>
static void dosomethingtoT(T& value)
{
value = 44;
}
};

int main()
{
long l;
foo::template dosomethingtoT(l); // why the template keyword??
return 0;
}

This is due to using a very old compiler, alternatively perhaps AIX
compiler.

The above compiles fine sans 'template' keyword with MSVC 7.1, g++ 3.4.4
and Comeau Online 4.3.3.
 
F

Frederick Gotham

Dilip posted:
Can someone explain to me why the
template keyword is required at the callsite of this static template
function?


The following compiles without error or warning for me with g++:

struct Arb {

template<class T>
void static Func(T &value)
{
value = 44;
}

};

int main()
{
int i;

Arb::Func(i);
}
 
D

Dilip

Alf said:
* Dilip:

This is due to using a very old compiler, alternatively perhaps AIX
compiler.

Strange.. I could've sworn I ran into linker errors before putting the
template keyword in front of the call. Now I removed it and everything
compiles and links fine. sigh...
FWIW I was using VC++ 8.0
 

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

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top