关于singleton 的面试题# JobHunting - 待字闺中
w*e
1 楼
看大牛的面试经历中写道 “面试中问道了设计模式, 但是只谈了singleton,
singleton谈了很多,
如何实现, 有什么问题”
我对于 singleton (classA) 实现的理解:
1. private constructor
2. define static member pointer variable (pointing to an instance of the
classA)
3. define static member function getInstance() returning the pointer or
reference
4. Inside the getInstance():
* when first time class, create an instance and save the address into
static member pointer;
* return the the static member variable
还有什么需要注意的吗? 可能会遇到什么问题?
先多谢了。
singleton谈了很多,
如何实现, 有什么问题”
我对于 singleton (classA) 实现的理解:
1. private constructor
2. define static member pointer variable (pointing to an instance of the
classA)
3. define static member function getInstance() returning the pointer or
reference
4. Inside the getInstance():
* when first time class, create an instance and save the address into
static member pointer;
* return the the static member variable
还有什么需要注意的吗? 可能会遇到什么问题?
先多谢了。