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
Post a Comment