用C++转发类声明,不完整类型

tej*_*004 8 c++

我使用clang编译器在C++中使用Forward Declaration有一个问题.这是我的代码.它将CReference成员中的数据指向为不完整类型.请帮忙

class Internal;

class CReference {
private:
    Internal data;
public:

    CReference () {}    
    ~CReference (){}
};

class Internal {
public:
    Internal () {}
    ~Internal () {}
};
Run Code Online (Sandbox Code Playgroud)

Kir*_*rov 17

当编译器不需要类型的完整定义时,前向声明很有用.换句话说,如果您将您更改Internal data;Internal* dataInternal& data,它将起作用.

使用时Internal data;,编译器需要知道整个定义Internal,才能够创建CReference类的结构.


And*_*rew 3

前向声明仅允许您使用对其的指针和引用,直到完整声明可用