首页 > 编程语言 > 详细

c++, singleton

时间:2020-01-28 09:08:22      阅读:74      评论:0      收藏:0      [点我收藏+]

0.

1. Implement a singleton class

class MySingleton{

public:

  static MySingleton*  const p_single;

private:

  MySingleton(void){cout << "private constructor." << endl;}  // private constructor

  MySingleton(const MySingleton&){}  //private copy-constructor

  MySingleton& operator=(const MySingleton&){}  // prevent assignment

};

MySingleton* const MySingleton::p_single = new MySingleton();  // private constructor will be called once

int main(){

  return 0;

}

the output will be: ( order matters)

private constructor.  

c++, singleton

原文:https://www.cnblogs.com/sarah-zhang/p/12237355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!