27.二阶构造模式

#include <iostream>
using namespace std;

class TwoPhaseCons
{
private:
    TwoPhaseCons()
    {

    }
    
    bool construct()
    {
        return true;
    }

public:
    static TwoPhaseCons * NewInstance();

};

TwoPhaseCons * TwoPhaseCons::NewInstance()
{
    TwoPhaseCons * ret = new TwoPhaseCons();

    if (!(ret && ret->construct()))
    {
        delete ret;
        ret = NULL;
    }
    
    return ret;

}


int main()
{
    TwoPhaseCons * obj = TwoPhaseCons::NewInstance();
    cout << "obj = " << obj << endl;
    
    return 0;

}

猜你喜欢

转载自www.cnblogs.com/kenantongxue/p/10745459.html