I
Imre
Hi
Please consider the following code:
template <class T>
struct Base;
template <template <typename> class T, typename P>
struct Base<T<P> >
{
typedef int Type;
};
template <typename P>
struct Derived:
public Base<Derived<P> >
{
Type v1;
typename Derived<P>::Type v2;
};
For some reason, the declaration of Derived::v1 doesn't compile, while
the declaration of v2 does, and I can't really understand why. I tested
it with VC++ 8.1 and the online Comeau compiler, the results were the
same.
What's the difference between Type and Derived<P>::Type inside
Derived<P>?
Some additional observations:
1. If I add a typedef int Type; into the primary Base template, then it
compiles with VC++ 8.1, but still won't compile with Comeau. I don't
see how this should change anything (the primary template is still not
used at all), so Comeau's behavior seems to make more sense.
2. If I remove the specialization, both compilers compile this code.
So, could someone explain this to me?
Thanks,
Imre
Please consider the following code:
template <class T>
struct Base;
template <template <typename> class T, typename P>
struct Base<T<P> >
{
typedef int Type;
};
template <typename P>
struct Derived:
public Base<Derived<P> >
{
Type v1;
typename Derived<P>::Type v2;
};
For some reason, the declaration of Derived::v1 doesn't compile, while
the declaration of v2 does, and I can't really understand why. I tested
it with VC++ 8.1 and the online Comeau compiler, the results were the
same.
What's the difference between Type and Derived<P>::Type inside
Derived<P>?
Some additional observations:
1. If I add a typedef int Type; into the primary Base template, then it
compiles with VC++ 8.1, but still won't compile with Comeau. I don't
see how this should change anything (the primary template is still not
used at all), so Comeau's behavior seems to make more sense.
2. If I remove the specialization, both compilers compile this code.
So, could someone explain this to me?
Thanks,
Imre