I just cannot imaginate a way to do a call to a function with genericity. I have a code which a have to call a function in two different classes in different moments.
I have A and B classes which I can access one time or other time. Or I access A or I access B. Not both in the same type.
I have code this program but I just cannot imagine how to do this. Or if this is good for performance or codding. I just want to eliminate the C class but I don't know how.
Any idea?
class MyClass { public: MyClass() {} //contructor padrão, não deve ser utilizado isoladamente virtual int a() = 0; virtual int b() = 0; int c() { return b(); } }; class A : public MyClass { public: int a() { return 1; } int b() { return 1; } int d() { return 1; } }; class B : public MyClass { public: int a() { return 1; } int b() { return 1; } int e() { return 1; } }; class C { public: A ca; B cb; enum TIPO { A, B }; TIPO Tipo; C(TIPO tipo) { Tipo = tipo; } int a() { switch(Tipo) { case A: return ca.a(); break; case B: return cb.b(); break; default: break; } } }; void main() { C c(C::B); c.a(); return; }