I am building a templated class “myTree” that includes a private struct “myNode”. I also have a private function “findNode” which I would like to return a myNode*. However, when I try and define the “findNode” I am getting 5 errors saying that seem to stem from the first error which says that I am missing a semicolon in between “myNode” and the “*”.
Here is the basic code:
template <size_t N, typename ElemType>
class myTree {
public:
//...
private:
struct myNode{
//...
};
myNode* findNode(const otherClass<N>& key);
};
template <size_t N, typename ElemType>
myNode* myTree<N, ElemType>::findNode(const otherClass<N>& key) {
return 0;
}
I tried changing the return type to void and the errors disappeared, meaning I assume that there is something wrong with the way I am using my struct.
The errors are:
1) Syntax error: missing ‘;’ before ‘*’
2) missing type specifier – int assumed
3) ‘N’ undeclared identifier
4) ‘ElemType’ undeclared identifier
5) ‘N’ undeclared identifier
These all point to the function declaration line ( myNode* myTree::findNode(const otherClass& key) { ).
myNode is an inner class and needs to be qualified in a return type: