Advertisement

Help on delete operator

Started by August 11, 2002 12:17 PM
2 comments, last by helpOnDelete 22 years, 4 months ago
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!
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.temp_proj; <br><br>*EDIT ARG! I thought |i| was disabled!<br><hr><br><i>I will not make a list of links… I will not make a list of links… I will not make a list of links… </i> <br><a href="http://www.invadersrealm.com" target="_blank">Invader's Realm</a><br><br><SPAN CLASS=editedby>[edited by - Invader X on August 11, 2002 8:02:22 PM]</SPAN>
Advertisement
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
He''ll just email a member of staff and get them to change his name to the new question.

____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement