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 - size_t 迭代的可变尺度

c++ - 如何在 Windows Mobile 中动态更改所有者绘制的列表框的高度?

c++ - C++ 中的强制转换顺序

c++ - 不兼容的模板实例

C - 将指向数组的指针传递给函数以打印数组

c - 使用双指针访问二维数组元素

c# - 是否有令人信服的理由反对使用 C# 关键字 "as"?

class - 方法未定义(类型没有方法)

c++ - QPushButton 不遵守水平扩展尺寸策略