小编mat*_*tor的帖子

当两个继承的类都需要一个不同的成员时,如何处理多重继承?

我有以下课程:

class ServoPart {
protected:
    virtual void doJob(byte* job) = 0;

private:
    bool moving;
    Servo servo;
};

// the following classes only have a constructor so I can use two ServoParts to inherit from
class Major: public ServoPart {};
class Minor: public ServoPart {};

class Arm: public Major, public Minor {
private:
    void move() {
        // do stuff
        if (target == current) {
            moving = false;
        }
    };

public:
    void doJob(byte* job) {/* do stuff */};
};
Run Code Online (Sandbox Code Playgroud)

我不能使用虚拟继承(我认为),因为 Major 和 …

c++ multiple-inheritance virtual-inheritance ambiguous

1
推荐指数
1
解决办法
56
查看次数