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