剑指offer

来源:互联网 发布:mac os没有刷新 编辑:程序博客网 时间:2024/06/05 12:03

1.赋值函数

CMyString& CMyString::operator = (const CMyString& str){    if(this != &str){        CMyString strtemp=CMyString(str);        char * ptemp=strtemp.m_pData;        strtemp.m_pData=m_pData;        m_pData=ptemp;    }    return *this;}

2.单例模式 singleton
http://www.2cto.com/kf/201606/520104.html

//Singleton.hclass Singleton  {public:    static Singleton* GetInstance();private:    Singleton() {}    static Singleton *singleton;};//Singleton.cppSingleton* Singleton::singleton = NULL;Singleton* Singleton::GetInstance(){    if(singleton == NULL)        singleton = new Singleton();    return singleton;}
0 0
原创粉丝点击