Re: Question on delete [] vs just plain delete

From: Efrat Regev (efrat_regev_at_yahoo.com)
Date: 01/29/05


Date: Sat, 29 Jan 2005 14:17:36 -0600


"DamonChong" <so_excited@excite.com> wrote in message
news:1107020524.756920.262920@c13g2000cwb.googlegroups.com...
> Thanks alot. Kind of silly I suppose to make such mistake. ;P
>

    No problem. BTW, explicit memory management is both very powerful, and
very prone to making "silly" mistakes (which I don't think are silly at
all). Consequently, perhaps you might want to read Peter Koch Larsen's
response (with which I completely agree).

    Specifically, you could write your code this way:

#include <vector>

std::vector<Object> obs[9];

for(int i = 0; i < 9; ++i)
    obs[i] = Object(i);

    Or if Object doesn't have a default constructor,

#include <vector>
#include <boost/shared_ptr.hpp>

std::vector<boost::shared_ptr<Object> > obs(9);

for(int i = 0; i < 9; ++i)
    obs[i].reset(new Object(i));

(You could google for boost smart_ptr for the above).



Relevant Pages

  • Re: The Pain and Relief of Culling Recordings
    ... recordings that really mean alot to me, and clearing out those which ... different when you get CDs as part of your business, ... I haven't made a mistake. ...
    (rec.music.classical.recordings)
  • Re: Ginkgo Biloba
    ... >I made the mistake of trying Ginkgo Biloba. ... >Now my prostate has flared up big time! ... > I'm in alot of pain. ...
    (sci.med.prostate.prostatitis)
  • Re: Hep c false positive
    ... I forgot to add that the women who was doing my blood made a mistake as ... She missed my vein and there was alot of trouble because of this. ...
    (sci.med.diseases.hepatitis)
  • Re: Thinking about trading/selling the 3 Stooges pin
    ... I think it would be a big mistake to sell it. ... you put alot of work into it. ... other family/friends. ...
    (rec.games.pinball)
  • Re: Thanks everyone for your responses!
    ... An SE enthusiast faced with a limited choice of drivers is no less ... prone than anybody else to mistake such a limited range for "full ...
    (rec.audio.tubes)