【问题标题】:Struct is not visible to .cpp结构对 .cpp 不可见
【发布时间】:2013-05-05 15:52:34
【问题描述】:

我在头文件中声明了一个结构体,你可以在下面看到它。

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 可见吗?

【问题讨论】:

  • Node 在哪个类中声明?你需要TheClassName::Node* ...,

标签: c++ visual-studio-2012 struct visibility


【解决方案1】:

假设CustomerList 是包含Node 的类。

CustomerList::Node* CustomerList::find(const int index){
    //some random code
}

CustomerList 方法中,您可以只说Node,但返回类型不同,您仍然需要使用CustomerList:: 进行限定

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 2016-02-29
    相关资源
    最近更新 更多