Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > delete() and ne...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 44772 of 48022
Post > Topic >>

delete() and new() on elements of an array created by new[]()

by "[rob desbois]" <rob.desbois@[EMAIL PROTECTED] > Apr 15, 2008 at 03:38 AM

This may be a very dumb question, but brain can't seem to find
anything to confirm/deny suspicion.

I have an array created with:
   FooClass* foo = new FooClass[numberOfFooObjects];

I want to be able to replace an element of that array at will with a
new FooClass.
Am I right in thinking that to delete foo[3], say, and replace with a
new FooClass, would require placement new? Would this be wise?

It seems that if I want to be able to replace elements at will with
newly constructed elements (rather than using the assignment
operator), that it would be better to do this:
   FooClass** foo = new FooClass*[numberOfFooObjects];
Then create each object on the heap and store the pointers instead.
Replacing elements is easy and obvious then...

I feel I'm being really stupid here, can someone enlighten a poor
confuzzled coder please?
TIA :-)
--rob
 




 3 Posts in Topic:
delete() and new() on elements of an array created by new[]()
"[rob desbois]"  2008-04-15 03:38:32 
Re: delete() and new() on elements of an array created by new[](
Michael DOUBEZ <michae  2008-04-15 14:50:51 
Re: delete() and new() on elements of an array created by new[](
"[rob desbois]"  2008-04-15 06:24:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:43:46 CDT 2008.