Jump to content
  • Advertisement


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



This topic is 6118 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 I have some trouble with "delete"... if you have a class like this: class B { private: int *index; public: B(){}; ~B(){delete[] index;} void func(){index = new index[5];} }; And a little program doing this: void main() { B *b; b = new B[1]; b[0].func(); delete[] b; } This would work fine... but if you took away the call to "func" it would crash when the destructor is called because no memory has been allocated for index. My question is how should I write the destructor so that it only deletes index if you have allocated memmory for index.

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!