But that doesn't work. I tried some random things in hopes that I'd get the combination right, but none of them worked.

What am I doing wrong? How do I fix this?

Thank you

04-17-2009

brewbuck

You can't reuse "T" as a template parameter. How could the inner class possibly distinguish between the two? Name it something else.

04-18-2009

yahn

I didn't want it to. The types always have to be the same. I guess this is achieved by having two separate variables anyways, though. Yes?

04-18-2009

brewbuck

Quote:

Originally Posted by yahn

I didn't want it to. The types always have to be the same. I guess this is achieved by having two separate variables anyways, though. Yes?

If the types have to be the same then the inner class does not need to be a template.

04-18-2009

yahn

Oh, that makes sense. How about when you want to return the nested type?

I have:

Code:

template<class T>
class H {
private:
class K;
// ...
};

Class K {
// ...
public:
K *doSomething();
// ...
};

template<class T>
H<T>::K *H<T>::K::doSomething() {
// ...
};

That gives the error : "dependent name is not a type prefix with 'typename' to indicate a type"

Do you know what I'm doing wrong?

Thank you

04-18-2009

laserlight

That looks wrong. If K is nested in H, then I would expect you to define it as:

Code:

template<class T>
class H<T>::K {
public:
K* doSomething();
};

though personally I would just define it within the definition of H. Anyway, once that is fixed, the next problem would be that in H<T>::K, the nested name K depends on the template parameter T. As such, it could, in theory, be interpreted not as a type name, but as an object name, and the rules say that it should be interpreted as a non-type name by default. As such, you should change to:

Code:

template<class T>
typename H<T>::K* H<T>::K::doSomething() {
// ...
}

04-18-2009

yahn

Sorry, I had properly declared the class, I just didn't write it done correctly when making the example. But, you're suggested works. Thank you

Now, I'm not getting any errors about the class, but when trying to compile I am getting unresolved external symbols to the functions of the class. What does that mean?

04-18-2009

laserlight

Quote:

Originally Posted by yahn

Now, I'm not getting any errors about the class, but when trying to compile I am getting unresolved external symbols to the functions of the class. What does that mean?

My guess is that you tried to separate the implementation of the class template into a source file, as would normally be done for classes. However, with templates, you generally have to put everything in the header file.