Template Member Functions of Template Classes

Discussion in 'C++' started by gogo1969@gmail.com, Feb 5, 2006.

  1. Guest

    Hello,

    I was wondering why the following code compiles with Intel C++ 8.0 and
    MS VC++ 7.1 but not with gcc 4.0.1 and Comeau 4.3.3:

    #include <iostream>

    template < class T > struct B {
    template < class O > static O CastTo( T t ) { return O( t ); }
    };

    template < class T > int convert( T t )
    {
    return B< T >::CastTo< int >( t );
    // ^
    // Comeau: Type not allowed
    }

    int main( int, char** )
    {

    std::cout << convert( 'c' );
    return 0;
    }

    The problem is this line: 'B< T >::CastTo< int >( t );'
     
    , Feb 5, 2006
    #1
    1. Advertising

  2. red floyd Guest

    wrote:
    > Hello,
    >
    > I was wondering why the following code compiles with Intel C++ 8.0 and
    > MS VC++ 7.1 but not with gcc 4.0.1 and Comeau 4.3.3:
    >
    > #include <iostream>
    >
    > template < class T > struct B {
    > template < class O > static O CastTo( T t ) { return O( t ); }
    > };
    >
    > template < class T > int convert( T t )
    > {
    > return B< T >::CastTo< int >( t );


    return B<T>::template CastTo<int>(t);
    > }
    >
    > int main( int, char** )
    > {
    >
    > std::cout << convert( 'c' );
    > return 0;
    > }
    >
     
    red floyd, Feb 5, 2006
    #2
    1. Advertising

  3. Kai-Uwe Bux Guest

    wrote:

    > Hello,
    >
    > I was wondering why the following code compiles with Intel C++ 8.0 and
    > MS VC++ 7.1 but not with gcc 4.0.1 and Comeau 4.3.3:
    >
    > #include <iostream>
    >
    > template < class T > struct B {
    > template < class O > static O CastTo( T t ) { return O( t ); }
    > };
    >
    > template < class T > int convert( T t )
    > {
    > return B< T >::CastTo< int >( t );


    try:

    return B< T >::template CastTo< int >( t );

    > // ^
    > // Comeau: Type not allowed
    > }
    >
    > int main( int, char** )
    > {
    >
    > std::cout << convert( 'c' );
    > return 0;
    > }
    >
    > The problem is this line: 'B< T >::CastTo< int >( t );'



    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Feb 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Razvan
    Replies:
    11
    Views:
    920
    Andrew Thompson
    Jul 17, 2004
  2. flounder
    Replies:
    4
    Views:
    512
    flounder
    Apr 2, 2009
  3. Hicham Mouline
    Replies:
    0
    Views:
    435
    Hicham Mouline
    Apr 23, 2009
  4. Hicham Mouline
    Replies:
    1
    Views:
    419
    Michael DOUBEZ
    Apr 24, 2009
  5. m0shbear
    Replies:
    2
    Views:
    349
Loading...

Share This Page