I don’t know how to express the dependency / relation of two classes that both will be subclassed. I think a example could help here:
Say I have two classes, Master and Slave.
The Master class has some methods, like void use(Slave * s) and Slave * generateFrom(int a)
class Master
{
public:
virtual void use(Slave * s) = 0;
virtual Slave * generateFrom(int a) = 0;
};
class Slave
{
};
Now I want to subclass both of these classes, but don’t want to lose the relation between them:
ConcreteMasterA ma();
ConcreteSlaveA * sa = ma.generateFrom(1);
ConcreteMasterB mb();
mb.use(sa); // THIS SHALL NOT WORK
Master * m = new ConcreteMasterA();
Slave * s = m->generateFrom(1); //s should now be a ConcreteSlaveA
m->use(s); // THIS SHALL WORK
Is there a way to express this relation with C++ classes / templates / whatever ?
Additional information
Perhaps I need to be more specific:
I have the class Arm which represents a robot arm. The state of an robot arm is specified by some number of parameters (angles, distances) and shall be represented by the class JointVariableVector
I want to control an arm using another class later on, but this class then shall only use methods exported by Arm and JointVariableVector.
Arm will be subclassed to provide the correct functionality per specific robot arm (e.g. SCARA or KUKA) and because of different structures I need subclasses from JointVariableVector (eg. one subclass with only 2 angles, and another with 3 angles and one distance)
I would do something like this
If you want a more strict test you could use
in your use function