inheritance

Hi,

i have class A and class B1,B2...B10 inherited from A.
Classes B1,B2,B3 shared one special methos. Where do I put this method?


sorry for my english :/
Maybe put in another layer:

1
2
3
4
5
6
7
8
9
10
11
class A {};

class Bx : A { /* add method here */ };

class B1 : Bx {};
class B2 : Bx {};
class B3 : Bx {};
class B4 : A {};
class B5 : A {};
...
class B10 : A {};


Another idea is to use multiple inheritance, but I've heard that is the goto of the 90's.

1
2
3
4
5
6
7
8
9
10
11
class A {};

class Bx : virtual A { /* add method here */ };

class B1 : Bx, virtual A {};
class B2 : Bx, virtual A {};
class B3 : Bx, virtual A {};
class B4 : A {};
class B5 : A {};
...
class B10: A {};


Last edited on
Thank you
Topic archived. No new replies allowed.