Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gimp

new CDog, delete CAnimal ???

This topic is 5844 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

Is this safe?
  
class CDog : public CAnimal {};

CDog* doggie = new CDog;

then

void DeleteAnimal(CAnimal* a)
{
   delete a;
}
  
(...blah, you know what I mean...) So, does this only deallocate the memory of an animal or does the OS store the original pointer against an allocation and remember how much was allocated to the doggie? Chris Brodie http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
Advertisement
I think this is testable...

Make a CDog class that contains a ''int test()'' function, that returns 1.

Then, create a CDog, delete it as an CAnimal, and then try to do pointer->test();

If the program only destroys the CAnimal part... then the last part of the CDog should still be in memory (it wasn''t removed), and since the pointer still points to what was *supposed* to be the beginning of the CDog... the function might still work.

In any case, if you find that this thing *works*, you know that delete doesnt remove the whole CDog.

If it doesn''t work, well, either it does remove it, or I didn''t get my memory jink right

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!