c++ - How can I avoid the Diamond of Death when using multiple inheritance? -


http://en.wikipedia.org/wiki/diamond_problem

i know means, steps can take avoid it?

a practical example:

class {}; class b : public {}; class c : public {}; class d : public b, public c {}; 

notice how class d inherits both b & c. both b & c inherit a. result in 2 copies of class being included in vtable.

to solve this, need virtual inheritance. it's class needs virtually inherited. so, fix issue:

class {}; class b : virtual public {}; class c : virtual public {}; class d : public b, public c {}; 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -