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

标签 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;
    int indexSize;

};

在我的 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 does not name a type”,即使它是在 index.h 的结构中定义的,并且我的私有(private) vector 变量可以具有类型 node*。

最佳答案

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

请注意,您可以在函数体内省(introspection)略 index::,因此只需在 cpp 文件的签名中说 index::node,因为这是在“全局 namespace ”内。

关于c++ - C++中未定义的结构类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12632060/

相关文章:

c++ - 我这里需要读写锁吗

c++ - 过滤 QStandardItemModel 或 QTreeView 中的项目

c++ - 在 C++ 中使用 key 生成 HMAC SHA256 哈希

c - 如何在函数内部将单个指针传递给结构并修改该结构变量?

c - 不应该 free() 接受 (void *const) 作为输入 arg

delphi - 如何跟踪双指针使用错误

c++ - 区分 typedef

c++ - LNK2005 - ATL 基类符号已定义 - 根本原因是什么?

c++ - POD 中的 static_assert 会破坏 POD 吗?

vba - 错误时类型不匹配