我想将两个类放在一个头文件中。一个是基类,第二个是从这个基类派生的,我的意思是这样的:
class Drawable{
public:
Drawable();
void setPosition(math::Vector3 position);
void draw();
};
class Box: public Drawable{} ;
但我收到错误“未定义对 `Drawable::Drawable()' 的引用”。在源文件中我有:
class Drawable {
public:
math::Vector3 position;
math::Vector3 rotation;
Drawable() {
position = math::Vector3(1.0, 1.0, 1.0);
rotation = math::Vector3(0.0, 0.0, 0.0);
}
void setPosition(math::Vector3 position) {
this->position = position;
}
void draw() {
}
};
class Box: public Drawable {
public:
void draw() {
glBegin(GL_TRIANGLES);
drawPoint(this->position + math::Vector3(1.0f, 1.0f, 1.0f));
drawPoint(this->position + math::Vector3(-1.0f, 1.0f, 1.0f));
drawPoint(this->position + math::Vector3(-1.0f, 1.0f, 1.0f));
drawPoint(this->position + math::Vector3(1.0f, 1.0f, 1.0f));
drawPoint(this->position + math::Vector3(1.0f, 1.0f, -1.0f));
drawPoint(this->position + math::Vector3(1.0f, -1.0f, 1.0f));
glEnd();
}
};
所以在我看来不可能做到这一点,因为头文件中的派生类还不知道基类的构造函数。我对吗?