the following is my index.h class
class index
{
struct node {
string item;
int counter;
vector<int> pageNumber;
};
public:
node* newNode (string word);
...
private:
vector<node*> indexStructure;
int lineCounter;
int indexSize;
};
In my index.cpp class I have a method definition as the following:
node* index::newNode (string word)
{
node* temp = new node();
temp.item = word;
temp.counter = 1;
temp.pageNumber = new vector <int> (10, -1);
temp.pageNumber[0] = lineCounter / 40;
return temp;
}
when I compile, it tells me “node does not name a type” even though it is defined in the struct in index.h and my private vector variable can have the type node*.
nodeis a nested class inindexand thus it is calledindex::nodewithin the global namespace.Note that you can omit the
index::from within the function body and thus only have to sayindex::nodein the signature in your cpp file, since this is within “global namespace”.