I have number of classes class 1, class 2, etc. inheriting class A and class B (but not all classes are inheriting both the classes).
Code looks like this:
class 1: public A, public B
{
getVar() { return mVar; }
}
class 2: public A, public B
{
getVar() { return mVar; }
}
class A
{
protected: int mVar;
}
class B
{
virtual int getVar()=0;
}
Here I am getting variable from class A in class B. But for that I have to implement getVar() { return mVar; } in all the classes(classN) which are deriving from both A and B.
What should be the correct design approach, so that I can give a default implementation and won't have to write same code in all the derived classes.
Aucun commentaire:
Enregistrer un commentaire