I’m having trouble understanding why the code below doesn’t compile — could someone please explain?
How do I access a typedef in a derived class from the base class?
template<class Derived>
struct Test
{
template<class T>
typename Derived::value_type foo(T);
};
struct Derived : public Test<Derived>
{
typedef int value_type;
};
At the time of declaring
Derived,Derivedis not yet a complete type — you’ve only just started declaring it! Hence in the specializationTest<Derived>, the template argument is an incomplete type, and thus you mustn’t refer to a nested name such asDerived::value_type— that’s circular logic.You could decycle the problem by making the return type a separate argument: