我有 2 个文件:
Point.h
:
class Point {
int x;
int y;
char* name;
public:
Point() { name = new char[5]; }
~Point() { delete[] name; }
};
和: Line.h
:
class Point;
class Line {
Point* p;
public:
Line() {
p = new Point[2];
....
...
}
~Line() {
delete[] p;
}
};
但是当我编译时,我得到了下一个错误:
deletion of pointer to incomplete type 'Point'; no destructor called
任何帮助表示赞赏!
原文由 Alon Shmiel 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要将
#include "Point.h"
添加到您的文件中Line.h
。您只能构造和删除 完整 类型。Alterntively, remove the member function definitions from
Line.h
, and put them in a separate fileLine.cpp
, and includePoint.h
andLine.h
in that 文件。这是一种典型的依赖减少技术,可以使代码更快地编译,尽管可能会失去某些内联机会。