C++ Can';t声明其他类的类字段类型
为什么我不能声明其他类的类字段类型?这给了我C4430错误:C++ Can';t声明其他类的类字段类型,c++,class,C++,Class,为什么我不能声明其他类的类字段类型?这给了我C4430错误: //Entity.h file class Entity { public: Box test; }; class Box { public: double length; // Length of a box double breadth; // Breadth of a box double heigh
//Entity.h file
class Entity
{
public:
Box test;
};
class Box
{
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
类
实体
在定义之前需要了解类框
。此外,由于在实体
类中包含框
的对象而不是指向的指针,它还需要知道类框
的大小(需要框
类的完整定义)和成员的定义(因为它将访问框::框
,以初始化实际字段),因此,在将框
作为实体
类中的字段之前,需要对其进行完整定义
class Box
{
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
class Entity
{
public:
Box test;
};
首先定义类框,然后定义类实体。在这个序列中,类实体还不知道接下来定义了一个类框。