c++----static 重复调用

class Base
{
public:
    Base()
    {
        cout << "cons" << endl;
    }
    ~Base()
    {
        cout << "de" << endl;
    }
    static Base* Default()
    {
        static Base b;
        return &b;
    }
};

int main(int argc, char** argv)
{

    for (int i = 0; i < 3; i++)
    {
        Base::Default();
    }
}

  只构造析构一次!

posted @ 2014-10-24 22:55  helloweworld  阅读(482)  评论(0编辑  收藏  举报