单例(Singleton),即一个类只有一个实例。

私有构造函数

class Singleton
{
private:
	Singleton() { };
	~Singleton() { };
	Singleton(const Singleton&);
	Singleton& operator=(const Singleton&);
public:
	static Singleton& getInstance() {
		static Singleton instance;
		return instance;
	}
};

 

相关文章:

  • 2021-05-18
  • 2021-10-17
  • 2021-07-17
  • 2021-07-07
  • 2021-11-28
猜你喜欢
  • 2022-01-31
  • 2021-08-08
  • 2021-09-29
  • 2021-12-09
  • 2021-08-20
  • 2022-02-25
  • 2021-09-28
相关资源
相似解决方案