1,限制类的对象只能生成在栈上
将 operator new 各种原型设为私有
#include <iostream> class OnlyOnStack { public: OnlyOnStack() { std::cout << "ctor!" << std::endl; } ~OnlyOnStack() { std::cout << "dctor!" << std::endl; } private:
1,限制类的对象只能生成在栈上
将 operator new 各种原型设为私有
#include <iostream> class OnlyOnStack { public: OnlyOnStack() { std::cout << "ctor!" << std::endl; } ~OnlyOnStack() { std::cout << "dctor!" << std::endl; } private: