Jump to content
  • Advertisement
Sign in to follow this  
Pet123

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

This topic is 3573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!