开发者

C++ multiple inheritance preventing diamond

Is there a way to define a class Foo in C++ so that

  1. I can inherit from it
  2. 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++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜