相关疑难解决方法(0)

是否可以在编译时阻止特定基类的多重继承?

我要做的是开发两个不同的基类,这些基类不应该在一个派生类中一起继承.有什么办法可以在编译时强制执行吗?

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?
Run Code Online (Sandbox Code Playgroud)

我知道文档是一个好主意,只是想知道它是否可行.

c++ multiple-inheritance

7
推荐指数
1
解决办法
842
查看次数

标签 统计

c++ ×1

multiple-inheritance ×1