码迷,mamicode.com
首页 > 编程语言 > 详细

c++, singleton

时间:2020-01-28 09:35:12      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:mat   prevent   oid   cout   static   order   family   event   class   

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

标签:mat   prevent   oid   cout   static   order   family   event   class   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!