Re: auto_ptr returns garbage
Additional info: I have changed all calls to CSettings::Instance() instead of storing the pointer.
Now the first pointer I initialize gets the address 0x00000007, and that seems to be the issue (because the singleton class was the one getting that address before).
Any ideas?
Re: auto_ptr returns garbage
I'm not really a fan of auto_ptr. It's hard to use correctly. While it seems like this usage *should* be fine, it might be easier to just avoid it. Stick with shared_ptr or scoped_ptr (or, if you have a bleeding-edge compiler, unique_ptr) for all your smart pointer needs.
The following is not 100% thread-safe on all compilers, but then, your above code isn't either, so I don't consider it a problem.....you can make either one thread-safe by ensuring you call Instance() at least once before spawning any threads.
Code:
CSettings * CSettings::Instance()
{
static CSettings instance;
return &instance;
}
Re: auto_ptr returns garbage
Thanks for your reply.
I have been studying this issue for some time, and I think it has something to do with a corrupted heap. Currently trying to figure out where this is coming from, but it's a pain in the ***.
Re: auto_ptr returns garbage
it looks like your static intialisation doesnt set it to NULL, but i'm not overly familiar with auto_ptr
Re: auto_ptr returns garbage
In the end, it had nothing to do with auto_ptr (it was just the first pointer initialized to get corrupted). It was a corrupted heap due to an external component I used. I have replaced the component and all seems to work fine now.
Thank you all for looking into my problem!