下面是我的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*。
最佳答案
node
是 index
中的嵌套类,因此在全局命名空间中称为 index::node
。
请注意,您可以在函数体内省(introspection)略 index::
,因此只需在 cpp 文件的签名中说 index::node
,因为这是在“全局 namespace ”内。
关于c++ - C++中未定义的结构类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12632060/