c++ - Is multiple inheritance needed? -


i have situation below:

class {     virtual void f() { /*some default impl here*/}     virtual void g() { /*some default impl here*/} };  class b : public {     virtual void f() { /* specific stuff , call parent's f()*/}     virtual void g() { /* specific stuff , call parent's g()*/} };  class c : public {     virtual void f() { /* specific stuff , call parent's f()*/}     virtual void g() { /* specific stuff , call parent's g()*/} };  class mixed /* don't know how derive*/ {     virtual void f() { /* call b::f()*/}     virtual void g() { /* call c::g()*/} }; 

i'm thinking multiple inheritance here. i.e., make mixed derived b , c. there known problems (for example, diamond problem).

another solution composition.

but correct solution, please advise :)

thanks in advance!

the fact each method has "do stuff" before calling parent causes problem.

one solution have a , b members in mixed class. can control need them in mixed::f() , mixed::g()

if need to, create base class base pure virtual functions f(), , g(). mixed can inherit that, , a, b , c. allude possibility when moot composition.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -