Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13828
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Question about destructors |
| Date | 2012-02-07 12:42 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <jgrnqu$d87$1@dont-email.me> (permalink) |
| References | <ba1d69e7-bd02-4c9a-9ab0-1f674fb3bc56@do4g2000vbb.googlegroups.com> <xn0hu2h1h91v2i4002@news.astraweb.com> <f7b07275-5374-4d4e-a679-44d9eb4cd719@eb6g2000vbb.googlegroups.com> <xn0hu2k3n9605fz003@news.astraweb.com> |
On 2/7/2012 12:34 PM, Asger Joergensen wrote:
> Hi Gus
>
> Gus Gassmann wrote:
>
>> Some of the code is not written by me, so I am afraid Fred`s solution
>> does not work. Let me then summarize, just to be absolutely clear:
> ...
>>
>> Will that do it?
>
> It looks fine to me, but allocating and deleting memory inside an object
> from the outside is really bad practice, You should at least ad a
>
> void setIntSize( int size );
> {
> delete[] intArray;
> intArray = new int[size]
> }
>
> to the object and then clean up in the destructor of the Object:
>
> ~Object()
> {
> delete[] intArray;
> }
>
> Do remember to zerro the intArray in the constructor.
> Object(): intArray(0){}
To the OP: Why not use std::vector? Or did you already answer that?
V
--
I do not respond to top-posted replies, please don't ask
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about destructors Gus Gassmann <horand.gassmann@googlemail.com> - 2012-02-07 06:53 -0800
Re: Question about destructors "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-02-07 16:11 +0100
Re: Question about destructors "Asger Joergensen" <Junk@Asger-P.dk> - 2012-02-07 15:38 +0000
Re: Question about destructors Gus Gassmann <horand.gassmann@googlemail.com> - 2012-02-07 09:13 -0800
Re: Question about destructors "Asger Joergensen" <Junk@Asger-P.dk> - 2012-02-07 17:34 +0000
Re: Question about destructors Victor Bazarov <v.bazarov@comcast.invalid> - 2012-02-07 12:42 -0500
Re: Question about destructors 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-07 23:39 -0800
Re: Question about destructors Ian Collins <ian-news@hotmail.com> - 2012-02-08 22:32 +1300
Re: Question about destructors Gareth Owen <gwowen@gmail.com> - 2012-02-08 17:51 +0000
Re: Question about destructors Gert-Jan de Vos <gert-jan.de.vos@onsneteindhoven.nl> - 2012-02-08 10:47 -0800
Re: Question about destructors SG <s.gesemann@gmail.com> - 2012-02-10 04:35 -0800
Re: Question about destructors 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-11 08:17 -0800
Re: Question about destructors Joshua Maurice <joshuamaurice@gmail.com> - 2012-02-07 15:12 -0800
Re: Question about destructors Juha Nieminen <nospam@thanks.invalid> - 2012-02-08 06:38 +0000
Re: Question about destructors Peter Remmers <p.remmers@expires-2011-04-30.arcornews.de> - 2012-02-09 00:30 +0100
Re: Question about destructors Peter Remmers <p.remmers@expires-2011-04-30.arcornews.de> - 2012-02-09 00:56 +0100
Re: Question about destructors Joshua Maurice <joshuamaurice@gmail.com> - 2012-02-09 14:34 -0800
Re: Question about destructors Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-13 17:48 +0000
csiph-web