Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Calling templated member of templated object

Reply
Thread Tools

Calling templated member of templated object

 
 
david@sunlightd.com
Guest
Posts: n/a
 
      06-22-2007
template< typename T >
void f( T & t )
{
t.g<int>();
}

MSVC 2005 compiles this without problems (yes, even when it's
instantiated). g++ gives errors. Comeau compiles in "relaxed" mode,
but in "strict" mode gives

"ComeauTest.c", line 4: error: type name is not allowed
t.g<int>();
^

"ComeauTest.c", line 4: error: expected an expression
t.g<int>();
^

Clearly, it's assuming the < is a less-than operator. What is the
"strict" way of doing this?
--
David

 
Reply With Quote
 
 
 
 
amparikh@gmail.com
Guest
Posts: n/a
 
      06-22-2007
On Jun 22, 10:03 am, (E-Mail Removed) wrote:
> template< typename T >
> void f( T & t )
> {
> t.g<int>();
>
> }

try

void f( T & t )
{
t.template g<int>();

}


>
> MSVC 2005 compiles this without problems (yes, even when it's
> instantiated). g++ gives errors. Comeau compiles in "relaxed" mode,
> but in "strict" mode gives
>
> "ComeauTest.c", line 4: error: type name is not allowed
> t.g<int>();
> ^
>
> "ComeauTest.c", line 4: error: expected an expression
> t.g<int>();
> ^
>
> Clearly, it's assuming the < is a less-than operator. What is the
> "strict" way of doing this?
> --
> David



 
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
Defining templated member function outside templated class chhenning C++ 5 02-13-2008 07:36 PM
Problem with member function of a templated class returning a pointer to an object of the same class Jahagirdar Vijayvithal S C++ 2 08-07-2005 10:13 AM
Subtypes of templated types (in templated functions) Marijn C++ 5 02-13-2004 09:50 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
implementing a templated struct within a templated struct RA Scheltema C++ 3 01-06-2004 11:25 AM



Advertisments