Hi daved:
This is what i do: (Couldnt copy/paste the original code but the structure is exactly the same
Code:
class CShared{
void doSomething() { }
};
class CFoo{
public:
static CShared* get_SharedInstance(){
static CShared* pObjShared = new CShared();
return pObjShared;
}
};
class CBar{
void Method1{
CShared* pObjShared = CFoo::get_SharedInstance();
std::cout << pObjShared << std::endl;
}
void Method2{
CShared* pObjShared = CFoo::get_SharedInstance();
std::cout << pObjShared << std::endl;
}
};
Method 1 prints: address1
Method 2 prints: address2
The application is multithreaded, better said, there is little change that the same thread who called method 1, calls method 2 on the same instance. Might this have something to do with it?
I use singleton classes alot in my application ( yeh i know ugly ) so is surely hope that this problem doesn't exists in those classes.
I solved it temporary by using a funvtion returning that object which works fine