1

When trying to compile the following code:

class Object
{
};

template <class OBJECT>
class Manager
{
public:
    typedef OBJECT Object_t;
};

template <class MANAGER>
class Container
{
    MANAGER::Object_t m_obj;
};

Container<Manager<Object> > container;

I get the following error:

prog.cpp:15: error: type ‘MANAGER’ is not derived from type ‘Container’

prog.cpp:15: error: expected ‘;’ before ‘m_obj’

Thanks

Ezra
  • 1,401
  • 5
  • 15
  • 33

1 Answers1

4

You need typename since the compiler does not know that MANAGER::Object_t refers to a type when it is parsing the template.

typename MANAGER::Object_t m_obj;

The first error message means the compiler is treating the scoped MANAGER:: token as trying to access a base class member of Container. The second error message indicates the compiler didn't know that m_obj was supposed to be a data member, since it didn't recognize the token before it to be a type.

jxh
  • 69,070
  • 8
  • 110
  • 193