m******r 发帖数: 61 | 1 I have one class. in order to make my application only have one instance of
this class,
I define a static count, when contructor is called the counter will ++.
my question is when counter >1, how class will destroy itself, when second
instance is trying to create.
Can I call destructor from constructor
except static variable, do we have other way to keep only one copy in my
application?
Thanks so much. | y*******g 发帖数: 6599 | 2 google singleton
of
【在 m******r 的大作中提到】 : I have one class. in order to make my application only have one instance of : this class, : I define a static count, when contructor is called the counter will ++. : my question is when counter >1, how class will destroy itself, when second : instance is trying to create. : Can I call destructor from constructor : except static variable, do we have other way to keep only one copy in my : application? : Thanks so much.
| Q******e 发帖数: 85 | 3 check more effective C++, how to limit the number of instance. | s****g 发帖数: 56 | 4 singleton for sure.
I don't think you can call dtr from ctr.
before ctr finishes, the object does not exist, yet.
of
【在 m******r 的大作中提到】 : I have one class. in order to make my application only have one instance of : this class, : I define a static count, when contructor is called the counter will ++. : my question is when counter >1, how class will destroy itself, when second : instance is trying to create. : Can I call destructor from constructor : except static variable, do we have other way to keep only one copy in my : application? : Thanks so much.
|
|