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(); } }
只构造析构一次!
时间: 2024-11-22 20:00:25