views:

46

answers:

1

Hi,

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?

+4  A: 

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.

Troubadour
@Troubadour: +1 - http://codepad.org/1BXCAoeW
Merlyn Morgan-Graham