Hello people,
Alright, my problem is something like this. I've declared a nested struct within a class template, and i want one of the member functions of the class to return an object of type struct. Somehow, i seem to be unable to do this defining the member function outside the class, but it does seem to work if i define the function within the class.
The actual code is quite involved, so i've contrived a little example to explain my problem:
#include <iostream>
template<class T>
class Tree {
struct Node { int a, b; };
Node createNode();
T b;
};
template<class T>
Node Tree<T>::createNode() {
std::cout<<"how are you\n";
Node n; n.a=n.b=10;
return n;
}
function createNode() is the problem here. Return type Node doesn't work. Return type Tree<T>::Node doesn't work. I've broken my head over this for quite a while, and am out of ideas. I'm using the Mingw compiler on Windows if that's of any relevance. The errors i get are something like:
expected constructor, destructor, or type conversion before "Tree"
Any help will be greatly appreciated. Thank you in advance.