有点冗长的标题,但这里有:
我有一种情况,我想防止两个类被同一个类或一个家族的任何类派生。在代码中:
class A;
class B;
class C: public A; //Yes.
class D: public B; //Yes.
class E: public A, public B; //Yes.
class F: public C, public B; //Yes.
class G: public A /*Disallow inheritance of B at this point somehow*/;
class H: public G, public B; //Error at this point...
class I;
class J: public G, public I; //...but not at this point.
在这种情况下,A 和 B 的私有成员对任何派生类都保持私有,而友谊会破坏这种设计。我怎么能做到这一点?