1 Use final
EG:
class B final
{
};
2 Use friend class and virtual inheritance
EG:
class A
{
private:
A()
{
cout << "A" << endl;
}
friend class B;
};
class B:virtual public A
{
};
In the above example, class B cannot be inherited, because if a class inherits B, because B virtual inherits A, the class that inherits B must call the constructor of A when constructing, but because the constructor of class A Private type, so contradictory