• Advertisement

Archived

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

Help on delete operator

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

I''m kind of new to C++, I might not know all the terminology, but here goes. Please help if you can. I have a class called Attribs, with protected member temp_proj. In a fuction, I did this: Attribs* multiProjections; multiProjections = new Attribs[2]; then: for(int i=0; i<2; i++) multiProjections.temp_proj = new string[6]; when i call delete, will the following suffice: delete [] multiProjections; // deletes everything or must i add this before the above call to delete: for(int i=0; i<2; i++) delete [] multiProjections.temp_proj; i ask because when i add this, this causes a lot of problems! i can''t test whether .temp_proj is deallocated because multiProjections is gone. i read somewhere that the delete operator and inheritance cause a lot of problems. if you can help please do!

Share this post


Link to post
Share on other sites
Advertisement
Yes, you must delete the dynamically allocated array. You're getting errors because you didn't specify which multiProjections to delete the array from.

Change:

for(int i=0; i<2; i++)
delete [] multiProjections.temp_proj;

To:

for(int i=0; i<2; i++)
delete [] multiProjections[ i ].temp_proj;

*EDIT ARG! I thought |i| was disabled!


I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader's Realm

[edited by - Invader X on August 11, 2002 8:02:22 PM]

Share this post


Link to post
Share on other sites
your post is helpondelete and your nick is helpondelete?

what if you need to ask another question ???

Its my duty, to please that booty ! - John Shaft

Share this post


Link to post
Share on other sites

  • Advertisement