How to handle multiple inheritance when both inherited classes need a distinct member?

I have the following classes:

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 */};
};

I can’t use virtual inheritance (I think) because the Major and Minor need to control one servo each which can’t be the same. However, when the Arm is done moving, it should set the moving member to false. Intellisense shows ServoPart::moving, when im typing moving.

Would this access of moving be ambiguous? If yes, how can I fix this? Is my assumption about virtual inheritance, that I can’t use it because I have two different servos, correct?

Source: Windows Questions C++

LEAVE A COMMENT