Sign in to follow this  
Pet123

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

Recommended Posts

Pet123    122
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]

Share this post


Link to post
Share on other sites
metalmidget    205
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.

Share this post


Link to post
Share on other sites
Pet123    122
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.

Share this post


Link to post
Share on other sites
elurahu    258
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this