摘要: 单线程class Singleton { private Singleton() {}; private static Singleton instance = null; public static Singleton createInstance() { if (instance == null) { instance = new Singleton(); } return i... 阅读全文
posted @ 2013-04-26 16:57 helloweworld 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 1、拥有一个私有构造函数,以确保用户无法通过new直接实例化它。 2、包含一个静态私有成员变量与静态公有方法。 3、instance方法负责检验并实例化自己,然后存储在静态成员变量中,以确保只有一个实例被创建。 核心:构造函数是私有的,有一个静态成员变量和静态方法。 仅适用于单线程 /*单例模式*/class Singleton { private static Singleton inst... 阅读全文
posted @ 2013-04-26 16:53 helloweworld 阅读(118) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <cstring>using namespace std;class MyString {public: MyString(); MyString(const char* cstr); MyString(const MyString &other); MyString& operator=(const MyString &other); si... 阅读全文
posted @ 2013-04-26 16:24 helloweworld 阅读(183) 评论(0) 推荐(0) 编辑
摘要: http://www.cppblog.com/xczhang/archive/2008/01/20/41508.html #include <iostream>#include <stdio.h>using namespace std;class Base1 {public: virtual void base1VirtualFun(int) { cout << "baseVirtualFun(f... 阅读全文
posted @ 2013-04-26 11:15 helloweworld 阅读(141) 评论(0) 推荐(0) 编辑