Aug 12, 2010 at 8:32am UTC
That's because the object is never destroyed.
Aug 12, 2010 at 8:35am UTC
But should it not be that the object be destroyed at the end of the program after main() exits. I tried the code with a little modification on static variables and the destructor is called but whereas here it is not. reason?
Aug 12, 2010 at 10:23am UTC
CSingleton sing
is not a pointer, make it CSingleton* sing
in GetSingleton()
, dont return *instance
you should return instance
, and change the return type from reference to pointer
Or
you could make it so;
CSingleton* sing = &CSingleton::GetSingleton();
Last edited on Aug 12, 2010 at 10:24am UTC
Aug 12, 2010 at 10:30am UTC
But should it not be that the object be destroyed at the end of the program after main() exits.
No. It is your responsibility to delete whatever you new, if you don't, that's your fault and you just created a memory leak.
Technically he is right, as the pointer ceases to exist when main ends. This does, however not apply to the memory pointed TO by the pointer.
Last edited on Aug 12, 2010 at 10:31am UTC
Aug 12, 2010 at 10:37am UTC
Having done the above changes as suggested by Skillless but ,
Now it is giving me the error
error C2440: 'return' : cannot convert from 'CSingleton *' to 'CSingleton &'
Last edited on Aug 12, 2010 at 10:38am UTC
Aug 12, 2010 at 11:18am UTC
Post the code..
Did you change the return type of GetSingleton to pointer instead of reference?
Aug 12, 2010 at 11:34am UTC
is sing a pointer?
Again, post the code =p
Aug 12, 2010 at 11:43am UTC
Or doesnt mean And, you did option A, and B, and thats not going to work
Anyway;
Did you change the return type of GetSingleton to pointer instead of reference?
bluecoder wrote:yes i did ..
CSingleton& CSingleton::GetSingleton()
Oh no you didn'
And change
CSingleton* sing = &CSingleton::GetSingleton();
to
CSingleton* sing = CSingleton::GetSingleton();
Last edited on Aug 12, 2010 at 11:45am UTC
Aug 12, 2010 at 1:02pm UTC
Sorry Skillless , first for not making the correct changes first .
And thanks , it worked .