Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Use of template keyword in callsite

Reply
Thread Tools

Use of template keyword in callsite

 
 
Dilip
Guest
Posts: n/a
 
      07-20-2006

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;
}

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-20-2006
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
 
Frederick Gotham
Guest
Posts: n/a
 
      07-20-2006
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);
}




--

Frederick Gotham
 
Reply With Quote
 
Dilip
Guest
Posts: n/a
 
      07-20-2006
Alf P. Steinbach wrote:
> * 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.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57