Skip to contentSkip to conversation

singleton pattern really necessary?

DISCUSSION Shriramana Sharma 1 participant 1 message Jul 22, 2007

lore
Share & tools
lore
#0 lore raw

I was wondering, if a person wants there to be only one instance of a class, they can simply do something like:

class {
<class definition here>
} classInstance ;

which automatically creates a single instance of a class. Why go to the extent of locking the constructor, copy constructor, operator= etc? The only possible thing (that I can think of) that cannot be done is conveniently passing it as an argument to a function. Is there any other reason that would make a class-name necessary?

Shriramana Sharma.