multiple inheritance - C++ Resolving the diamond problem -



multiple inheritance - C++ Resolving the diamond problem -

couldn't diamond problem resolved using first inherited declaration found? mean,

public class { public virtual int getint(); }; public class b : public { public int getint() {return 6;} }; public class c : public { public int getint() {return 7;} }; public class d: public b, public c {};

for class d, since b listed first, couldn't default (when it's ambiguous) utilize b::getint() if d::getint() called? kind of how path environment variable works in unix , other os's; if 2 things exist same name in different locations in path variable, first location shall used default (unless otherwise qualified).

edit: 'first' inherited declaration found mean according simple left-to-right depth-first order

edit#2: updated above implementation more diamond-like.

it's buggy solution. think happen in next case:

public class { public int getint() {return 5;} public float getfloat() {return 5.0;} }; public class b { public int getint() {return 6;} public float getfloat() {return 6.0;} }; public class c { public int getint() {return 7;} public float getfloat() {return 7.0;} }; public class d: public a, public b, public c {}

suppose 1 want d::getint homecoming 5 while developer wants d::getfloat homecoming 7.0 (thus, different functions resolved different ancestors). sec developer alter order of inheritance , bug creep in code paths depending on getint.

c++ multiple-inheritance diamond-problem

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -