Hello,
Take a look at this piece of code:
--------------------------------------------------
// A: PARTIAL SPECIALIZATION WORKS HERE JUST FINE: /////
template<class T, class T1>
struct A
{
T t1;
typedef T Type;
Type f() { return Type(); }
};
template<class T>
struct A<T,int> : public A<T,char> // I.E. INHERITS FROM GENERAL TYPE
{
T t2;
Type g() { return Type(); } // NO ERROR, SEE NOTE BELOW
};
// B: PROBLEM OCCURS: ///////////////////////////////////
template<class T, class T1>
struct B
{
};
template<class T,class T1>
struct B<T*,T1>
{
T* tp1;
typedef T Type;
Type f() { return Type(); }
};
template<class T>
struct B<T*,int> : public B<T*,char> // I.E. INHERITS FROM GENERAL TYPE
{
T* tp2;
// typedef typename B<T*,char>::Type Type; // WITH THIS LINE, NO ERROR
Type g() { return Type(); } // ERROR!
// IT SEEMS LIKE THIS CLASS CANNOT REACH THE TYPEDEF DEFINED IN ITS PARENT
// WITH CLASS A -NO SPECIALIZING TO POINTER TYPE- THIS WORKED.
};
int main()
{
A<int,int> a; // TYPE SPECIALIZED TO int
int f = a.f();
B<int*,int> b; // TYPE SPECIALIZED TO pointer,int
int g = b.f();
return 0;
}//main()
----------------------------------------------------------
The error message generated:
error C2146: syntax error : missing ';' before identifier 'g'
error C2501: 'B<T*,int>::Type' : missing storage-class or type specifiers
Is this a bug or some strange language feature I haven't run into before?
Thx,
Gus