单例模式:设计模式的一种,保证某个类永远只创建一个对象
- 1.构造函数私有化
- 2.定义一个私有的static成员变量指向唯一的那个单例对象
- 3.提供一个公共的访问单例对象的接口
#include <iostream>
using namespace std;
class Person {
private:
static Person* teacher; //定义一个唯一的对象
Person()
单例模式:设计模式的一种,保证某个类永远只创建一个对象
#include <iostream>
using namespace std;
class Person {
private:
static Person* teacher; //定义一个唯一的对象
Person()