1

I have this example code: #include

template<class T>
class Class
{
public:
    typedef boost::shared_ptr<Class<T> > Ref;
};

template<class T>
class Class2
{
public:
    Class<T>::Ref getAReference() {return Class<T>::Ref(new Class<T>);};
};
int main(){}

When I try to compile it, I get:

test.cpp:14: error: type ‘Class<T>’ is not derived from type ‘Class2<T>’
test.cpp:14: error: expected ‘;’ before ‘getAReference’

I do not get it, why does it not work? How do I make it work?

Nathan
  • 515
  • 2
  • 7
  • 14
  • Are you showing the whole code? You are clearly lacking a `typename`, but if that is the error message you get from a missing `typename` with exactly the code you posted the compiler diagnostics are strange to say the least. The first line of error seems to point to a inheritance relation that is not present in the code. – David Rodríguez - dribeas Aug 13 '10 at 11:27
  • I agree that this is strange, but I am showing the whole code and a typename made the message go away. – Nathan Aug 13 '10 at 11:40

1 Answers1

4

You need to tell the compiler that Ref is a type by using typename i.e.

typename Class<T>::Ref getAReference() {return Class<T>::Ref(new Class<T>);};

This question discusses it further.

Community
  • 1
  • 1
Troubadour
  • 13,334
  • 2
  • 38
  • 57