On 5/10/06, amol <gajewar.amol@xxxxxxxxxxxxxxx> wrote:
Following is the code which works on windows but can't work with g++ template < class my_type> class mytypedef { public : typedef my_type new_type; }; template <class my_type> class sample: public mytypedef < my_type > { public : new_type var; }; Error : new_type doest not name a type. Why is it happening? What is solution for this problem? Amol Gajewar
Solution ,as suggested by g++(4.0.2) itself works myshec-linux:~ # g++ -c temp.cpp error: 'new_type' does not name a type note: (perhaps 'typename mytypedef<my_type>::new_type' was intended) when i used what g++ suggested (the part which follows note :it worked ) what i think is : first compiler will not look for definition of new_type in the base class scope ,there was a similar thread today which pointed to this URL http://gcc.gnu.org/ml/gcc-help/2004-04/msg00382.html second , the typename keyword is needed ,otherwise the compiler will not believe that new_type is a type , it will assume it as a static member or a enum or an object ,but it wont-cannot know that it is a type , until the template is instantiated...so u have to use typename. VC++ rules might be different , but this is the standard. HTH Digz