I have a MotorDefinition class and an abstract class called Motor:
class MotorDefinition {
public:
MotorDefinition(int p1, int p2, int p3) : pin1(p1), pin2(p2), pin3(p3) {}
int pin1 = -1;
int pin2 = -1;
int pin3 = -1;
};
class Motor {
public:
Motor(MotorDefinition d) : definition(d) {}
virtual void forward(int speed) const = 0;
virtual void backward(int speed) const = 0;
virtual void stop() const = 0;
protected:
MotorDefinition definition;
};
My Zumo vehicle has two motors:
class MotorTypeZumoLeft : public Motor {
MotorTypeZumoLeft(MotorDefinition def) : Motor(def) {}
void Motor::forward(int speed) const {}
void Motor::backward(int speed) const {}
void Motor::stop() const {}
};
class MotorTypeZumoRight : public Motor {
MotorTypeZumoRight(MotorDefinition def) : Motor(def) {}
void Motor::forward(int speed) const {}
void Motor::backward(int speed) const {}
void Motor::stop() const {};
};
class MotorTypeZumo {
public:
MotorTypeZumo(MotorTypeZumoLeft *l, MotorTypeZumoRight *r) : left(l), right(r) {}
protected:
MotorTypeZumoLeft *left;
MotorTypeZumoRight *right;
};
Unfortunately (for me), this doesn't compile:
MotorDefinition lmd(1, 2, 3);
MotorTypeZumoLeft *leftMotor(lmd);
MotorDefinition rmd(4, 5, 6);
MotorTypeZumoRight *rightMotor(rmd);
MotorTypeZumo motors(*leftMotor, *rightMotor);
I think I am missing some fundamental concepts and I am certainly messing up some syntax. Can you help me define this correctly, please.