J
jason.cipriani
I have some code like this that won't compile:
template <typename T> class MyClass {
public:
class Nested { };
Nested f ();
};
template <typename T> MyClass<T>::Nested f () { // <---problem
return Nested();
}
"Nested" is a non-template class, nested inside the template class
"MyClass". The MyClass member function f() returns a "Nested", and is
defined outside of the class declaration. I receive the following
error from Comeau (and similar errors from other compilers):
"ComeauTest.c", line 7: error: nontype "MyClass<T>::Nested [with T=T]"
is not a
type name
template <typename T> MyClass<T>::Nested f () {
What is the correct syntax to use here? I can't figure out how to make
this work (or if it's just not possible). Putting the definition of f
() right in the class declaration does work fine, but I'd like to keep
it outside, but mostly I'm curious about the syntax.
Thanks,
JC
template <typename T> class MyClass {
public:
class Nested { };
Nested f ();
};
template <typename T> MyClass<T>::Nested f () { // <---problem
return Nested();
}
"Nested" is a non-template class, nested inside the template class
"MyClass". The MyClass member function f() returns a "Nested", and is
defined outside of the class declaration. I receive the following
error from Comeau (and similar errors from other compilers):
"ComeauTest.c", line 7: error: nontype "MyClass<T>::Nested [with T=T]"
is not a
type name
template <typename T> MyClass<T>::Nested f () {
What is the correct syntax to use here? I can't figure out how to make
this work (or if it's just not possible). Putting the definition of f
() right in the class declaration does work fine, but I'd like to keep
it outside, but mostly I'm curious about the syntax.
Thanks,
JC