Did I missed something here?
In the main function, this code just works fine:Code:template<typename T>class A { public: template<typename T2> A<T2> toA() { return A<T2>(); } };
I think there is nothing wrong with the code,Code:A<int> a1; A<float> a2 = a1.toA<float>(); // Works fine! As expected.
but G++ gives me syntax errors:
I tried to compile it in VC and it gave me a strange error message:Code:template<typename T>class B { A<T> a; public: B( void ) { ; } B( const A<T> &a ) { this->a = a; } template<typename T3> B<T3> toB() { return B<T3>( a.toA<T3>() ); // error? // ???.cpp: In member function `B<T3> B<T>::toB()': // ???.cpp:9999: error: expected primary-expression before '(' token // ???.cpp:9999: error: expected primary-expression before '>' token // ???.cpp:9999: error: expected primary-expression before ')' token } };
And then I tried another way:Code:B<int> b; b.toB<double>(); // x:\somewhere\code.cpp(9999) : error C2062: type 'double' unexpected
Thank's in advance.Code:template<typename T3> B<T3> toB() { A<T3> a1 = this->a.toA<T3>(); // won't work A<T> a2 = this->a; A<T3> a3 = a2.toA<T3>(); // silly, this way won't work too }
EDIT: Sorry for my English.. T.T



LinkBack URL
About LinkBacks


