c ++中未定义的结构类型

Sun*_*Liu 0 c++ struct types pointers

以下是我的index.h类

class index
{

struct node {
        string item;
        int counter;
        vector<int> pageNumber;
    };

public:
    node* newNode (string word);
    ...

private:
    vector<node*> indexStructure;
    int lineCounter;
    int indexSize;

};
Run Code Online (Sandbox Code Playgroud)

在我的index.cpp类中,我有一个方法定义如下:

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;

}
Run Code Online (Sandbox Code Playgroud)

当我编译时,它告诉我"节点没有命名类型",即使它在index.h中的结构中定义,并且我的私有向量变量可以具有类型node*.

lee*_*mes 7

node是一个嵌套类,index因此它index::node在全局命名空间中调用.

请注意,您可以省略index::函数体中的from,因此只需index::node在cpp文件的签名中说明,因为它位于"全局命名空间"中.