C++ multiple inheritance preventing diamond
Is there a way to define a class Foo in C++ so that
- I can inherit from it
- I can't "diamond 开发者_高级运维inherit" from it
I.e.
class Cat: public Foo{} // okay
class Dog: public Foo{} // okay
class Weird: public Cat, public Dog {} // I want this to throw a compiler error
Cprogramming.com Tutorial: Solving the Diamond Problem in C++ with ...
http://www.cprogramming.com/tutorial/virtual_inheritance.html
Try This
For this type problem can be Avoid or solve by interface.
Another source of information:
http://www.parashift.com/c++-faq-lite/multiple-inheritance.html
Actually the whole C++ faq little it is really worth reading if you are programming on C++.
精彩评论