【发布时间】:2012-02-04 00:02:40
【问题描述】:
我想做的是开发两个不同的基类,它们不应该在一个派生类中一起继承。有什么办法可以在编译时强制执行吗?
class Base1 {};
class Base2 {};
class Derived1 : public Base1 {} // OK!
class Derived2 : public Base2, public Other {} // OK!
class Derived3 : public Base1, Base2 {} // Can I force the compiler to complain?
Derived1 d1; // OK!
Derived2 d2; // OK!
Derived3 d3; // Or can I force the compiler to complain here?
我知道documentation 是个好主意,只是想知道它是否可能。
【问题讨论】:
-
我认为拥有一个私有构造函数就可以了。但它也会禁用
Derived2案例。 -
写“不要这样做!”还不够吗?在文档中?
-
开发者阅读文档?