我在头文件中声明了一个结构体,你可以在下面看到它。
private:
struct Node{
Customer data;
Node *next;
Node *prev;
};
Node* find (const int index) const;
并声明了一个返回 Node*
private 的函数。
然而,当我尝试在我的 cpp 文件中实现函数 find
时,它给出了一个错误,提示“identifier Node is undefined”。
Node* CustomerList::find(const int index){
//some random code
}
问题是什么,难道 Node
不应该对 .cpp 可见吗?
最佳答案
假设 CustomerList
是包含 Node
的类。
CustomerList::Node* CustomerList::find(const int index){
//some random code
}
在 CustomerList
方法中,您可以只说 Node
但返回类型不同,您仍然需要使用 CustomerList::
进行限定/p>
关于c++ - 结构对 .cpp 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386308/