My question is, why does the following code not compile:
template<typename t> class c1
{
public:
typedef int type_name;
void fn1(type_name x) {}
};
template<typename t> class c2 : public c1<t>
{
public:
void fn2(type_name x) {}
};
While the following does:
class c1
{
public:
typedef int type_name;
void fn1(type_name x) {}
};
class c2 : public c1
{
public:
void fn2(type_name x) {}
};
As you see, the only difference is that in the first case the classes are templates. Gcc and Clang complain that type_name is not defined in the second class (only in template version). Are typedefs not inherited from parent class? If so, why does it work on non-template version? Is there some exception when using typedefs from templates?
Also, I know that I can make this work with fully-qualified type name, i.e. 'typename c1::type_name'. I just want to know if this is some C++ restriction or compiler bug.