C++多重继承防止钻石

ano*_*non 14 c++ inheritance virtual-inheritance diamond-problem

有没有办法在C++中定义类Foo,以便

  1. 我可以继承它
  2. 我不能从它"钻石继承"

class Cat: public Foo{} // okay
class Dog: public Foo{} // okay
class Weird: public Cat, public Dog {} // I want this to throw a compiler error
Run Code Online (Sandbox Code Playgroud)

rat*_*tty 6

Cprogramming.com教程:使用C++解决C++中的钻石问题

http://www.cprogramming.com/tutorial/virtual_inheritance.html

试试这个

对于这种类型的问题可以是避免或通过接口解决.