j******n 发帖数: 271 | 1 How to ensure a class is derived directly no more than once in C++? That
is, how to prevent a class having more than one direct subclass? At
compile time, please. |
J*****n 发帖数: 4859 | 2
private constructor?
【在 j******n 的大作中提到】 : How to ensure a class is derived directly no more than once in C++? That : is, how to prevent a class having more than one direct subclass? At : compile time, please.
|
j******n 发帖数: 271 | 3 That would work if you know the name of the class your client is to use,
like the following:
// your class
class Derived;
class Base
{
friend class Derived;
Base();
};
// your client:
class Derived : Base
{};
But that puts an unwanted restriction on your client.
【在 J*****n 的大作中提到】 : : private constructor?
|
s***e 发帖数: 267 | 4 making the constructor a protected memeber?
【在 j******n 的大作中提到】 : How to ensure a class is derived directly no more than once in C++? That : is, how to prevent a class having more than one direct subclass? At : compile time, please.
|