Class-dilemma; One variable should contain all three classes
Lets say I have these three classes, I mean, lets just not say, but I really have these three classes and they cannot be changed;
Code:
class A
{
};
class B : public A
{
};
class C : public A
{
};
How should I go about creating one variable which then will contain one object from each class?
(I know I would have solved this by making C : public B... that is not an option)
If I go:
C class = new C(); the variable name "class" only contains C and A.
If I do:
B class = new B(); the variable name "class" only contains B and A.
If I do:
A class = new A(); the variable name "class" only contains A.
Can I put two pointers in A, one that points to B and one that points to C? But that would again create two new instances of A? right?
If I add a pointer in B to point to C (or vice versa) it will leave me with two A objects (one for the class, one for the pointer).
Am I Clear? :)
Ideas very much appreciated! :)