在C ++中继承bool字段

时间:2014-04-22 18:16:27

标签: c++ inheritance boolean

我对C ++很新。我创建了一个名为shape.h的接口,我有两个类,我希望它们从中继承:plane.cppsphere.cpp(两者都有自己的.h文件。不知道它是否相关,但我认为值得一提)。 shape.h的其中一个字段是bool isRound,我希望sphere.cpp构造函数将其更改为trueplane.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 值。 我在这里做错了什么?

0 个答案:

没有答案