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

C++ c+中未定义的结构类型+;,c++,pointers,types,struct,C++,Pointers,Types,Struct,下面是我的index.h类 class index { struct node { string item; int counter; vector<int> pageNumber; }; public: node* newNode (string word); ... private: vector<node*> indexStructure; int lineCounter;

下面是我的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;

};
类索引
{
结构节点{
字符串项;
整数计数器;
向量页码;
};
公众:
node*newNode(字符串字);
...
私人:
向量指数结构;
内线计数器;
int索引化;
};
在我的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;

}
node*索引::newNode(字符串字)
{
node*temp=新节点();
临时项目=单词;
温度计数器=1;
temp.pageNumber=新向量(10,-1);
临时页码[0]=行计数器/40;
返回温度;
}

当我编译时,它告诉我“node不命名类型”,即使它是在index.h的结构中定义的,并且我的私有向量变量可以让类型node*

将其更改为
index::node*index::newNode(字符串词)
。以您尝试的方式执行此操作所需的作用域直到函数名结束后才建立。

node
index
中的嵌套类,因此在全局命名空间中称为
index::node


请注意,您可以在函数体中省略
索引::
,因此只需在cpp文件的签名中说
索引::节点
,因为这在“全局名称空间”中。

我应该给您一个-1,因为您用同样的内容打败了我。:-(@ThomasMatthews抱歉,我认为这种情况经常发生,特别是在这样的问题上,这些问题可以很快得到回答:)@leems你是对的。我误读了函数的定义。谢谢。我强烈建议不要使用嵌套类,主要是因为这个原因。当您获得更多经验时,您可以为嵌套类开发自己的规则。对于你的学习来说,这只是一个巨大的痛苦;不值得。旁白:你的意思是
temp->
,而不是
temp.