Name: Anonymous 2007-02-04 0:44
In the following program I want g() to be prototyped inside the class X and defined later. I can't get g() to compile though no matter how many variations I try. f() compiles fine.
template <typename T>
class X
{
public:
class Y { };
Y f() {Y y; return y;} //Okay function.
Y g(); //Problematic function.
};
//Compiler Error Here: expected constructor, destructor, or type conversion before 'X'
template <typename T>
X<T>::Y X<T>::f()
{
Y y;
return y;
}
int main()
{
X<int> x;
x.f(); //This works.
x.g(); //Call to problematic function.
}
template <typename T>
class X
{
public:
class Y { };
Y f() {Y y; return y;} //Okay function.
Y g(); //Problematic function.
};
//Compiler Error Here: expected constructor, destructor, or type conversion before 'X'
template <typename T>
X<T>::Y X<T>::f()
{
Y y;
return y;
}
int main()
{
X<int> x;
x.f(); //This works.
x.g(); //Call to problematic function.
}