Why is Singleton a better choice than Global Objects
This question already has an answer here:
他们是懒惰的构造:
LargeObject global; // Large object is always constructed.
class LargeObject_Singelton
{
public: static LargeObject& getInstance()
{
static LargeObject instance; // This object is not created until the first
return instance; // time getInstance() is called.
} // If you never use it this can be important.
};
链接地址: http://www.djcxy.com/p/82164.html
上一篇: 实现接口的单例类