开发者

C++ multiple inheritance preventing diamond

开发者 https://www.devze.com 2022-12-21 11:22 出处:网络
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

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

精彩评论

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