- 不能在堆上创建的类
- 不能在栈上创建的类
- 不能被继承的类
构造函数私有化,则子类不能调用父类的构造函数,实现类不能被继承
class NonInherit
{
public:
static NonInherit instance()
{
return NonInherit();
}
private:
NonInherit()
{}
};
在c++11中可以直接使用final来防止类被继承
class NonInherit final
{};