C++多重继承阻止钻石
有没有办法在 C++ 中定义类 Foo 这样
- 我就可以继承它,
- 我不能从中“钻石继承”,
即
class Cat: public Foo{} // okay
class Dog: public Foo{} // okay
class Weird: public Cat, public Dog {} // I want this to throw a compiler error
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cprogramming.com 教程:用 ... 解决 C++ 中的钻石问题
http://www.cprogramming .com/tutorial/virtual_inheritance.html
尝试一下
对于这种类型的问题可以通过接口来避免或解决。
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.
另一个信息来源:
http://www.parashift.com/c++ -faq-lite/multiple-inheritance.html
实际上,整个 C++ 常见问题解答很少,如果您正在使用 C++ 进行编程,那么它确实值得一读。
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++.