what could be the reason? (0xCDCDCDCD) [fixed]

Started by
3 comments, last by elurahu 15 years, 8 months ago
hi everybody i have a class instance which has a pointer member, the struct looks like this :

class someclass_t
{
public :
	class another_t
	{
	public :
		void doSomething()
		{
			...
		}
	};
	
public :
	another_t *_another;
};

void main()
{
	someclass_t *scPtr = 0;
	...
	scPtr->_another->doSomething();  // wrong here when step into doSomething
}


when step into doSomething() at the line with comment, 'this' pointer (the another_t itself) becomes 0xCDCDCDCD while everything looks just correct before entering the function (scPtr and _another both are valid), this is wired, anyone here ever had the same problem could you please shed some light what could be the reason? thanks a lot. (runtime c library : multi-thread debug dll, RTTI is turned on) thank you. [Edited by - Pet123 on August 11, 2008 4:22:45 AM]
Advertisement
Magic number (programming)
0xCDCDCDCD: Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory
Should give a good picture of the cause of the memory value. :-)
---Sudet ulvovat - karavaani kulkee
In case that wasn't clear enough for you:
You can't dereference a pointer that hasn't been initialised. With the code you have, "_another" is a pointer to type "another_t", but it isn't actually pointing to anything- that's what the CDCD stuff means.
Basically this means you have to create something for "_another" to point to in "scPtr"'s constructor:
_another = new another_t;

You'll also need to destroy _another when scPtr is destroyed, otherwise you'll have a memory leak:
delete _another;


cheers,
metal
PS- If you've done both of those but not posted it, then it's most likely lack of a copy constructor or operator=() for another_t, which I can explain if you want.
thanks metalmidget and Naurava kulkuri, its ok now -- the only thing i did was to clean the whole solution and re-compile. seems polluted intermediate files will bring un-expected result, but how it was polluted? anyway if anyone else has the similar problem please try to make a clean recompile first, it may solve your problem. thanks again for the replys.
Hey Pet123. Well unless you're initializing the _another member variable somewhere cleaning and recompiling is not going to save you :) I appreciate you're program is running now but I can assure you it was not the clean/recompile that did it :)

This topic is closed to new replies.

Advertisement