Where have all my instances gone, they are gone, everyone...

rifter1818

Well-known member
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
ok, it seems to me like something is acting as garbage collection on my c++ code, and i would like it to stop,.. every time i call a constructor inside a function by the time it exits that function the pointer i constructed is now pointing at nothing whatsoever.... ive found ways of avoiding it in some cases but not all and need help.
What i want to word
Code:
void construct(classtype1 *variable)
{
       variable = new classtype1();
}
works fine in the function but once it ends the function variable is now set to god knows what.
however
Code:
void construct(classtype1& variable)
{
     variable = classtype1();
}
is fine.
So through my train of logic it would seem that this mysterious garbage collection (which to my knowledge of c++ shouldnt exist) seems to have decread that pointers are too hard to track and therefor dont exist outside of that function so it can go ahead and cleanup the variable i just created. This problem has caused me hours of headaches.. Is there any way to make the pain stop?

Oh yes im using the win32 console application as im not coding in managed c++ (where having GC running would make sence to me).

edit:
another instance of this problem has been when i created a deque of pointers, in that case to various objects like... the asteroids in my asteroids game, then i created a function which added a pointer to this list, the function ran fine, i checked inside the function everything was fine, but once that function ended, the menace came and destroyed my asteroid, causing my application to crash when it tried to render the random garbage the pointer now pointed at.
 
variable declaration

Where have you declared your variable, because if you declare it localy inside the constructor or function if you reach the end of that block of code the variable goes out of scope ... If i am not mistaking
 
Back
Top