• Advertisement


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


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