我对C ++很新。我创建了一个名为shape.h
的接口,我有两个类,我希望它们从中继承:plane.cpp
和sphere.cpp
(两者都有自己的.h
文件。不知道它是否相关,但我认为值得一提)。
shape.h
的其中一个字段是bool isRound
,我希望sphere.cpp
构造函数将其更改为true
和plane.cpp
构造函数,以将其更改为false
}。这就是我在球体上做到的方式:
sphere::sphere(Vector3f Center, float Radius, Vector3f Ka, Vector3f Kd, Vector3f Ks, float Shininess) : shape(Ka, Kd, Ks, Shininess){
this->ka = Ka;
this->kd = Kd;
this->ks = Ks;
this->radius = Radius;
this->center = Center;
this->shininess = Shininess;
this->isRound = true;
}
并在飞机上:
plane::plane(Vector3f Ka, Vector3f Kd, Vector3f Ks, Vector3f Normal, Vector3f Point, float shininess) : shape(Ka, Kd, Ks, shininess){
this->shininess = shininess;
this->ka = Ka;
this->kd = Kd;
this->ks = Ks;
this->normal = Normal;
this->point = Point;
this->isRound = false;
}
这就是shape.h
的样子:
class shape
{
protected:
Vector3f color;
public:
Vector3f ka;
Vector3f kd;
Vector3f ks;
int shininess;
bool isRound; ...
但是,无论我创建什么形状,它们都会获得 true 值。 我在这里做错了什么?