Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6919
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: HEAP error when trying to use free() help needed |
| Date | 2011-06-20 17:17 +1200 |
| Message-ID | <9683f5FsmeU3@mid.individual.net> (permalink) |
| References | <75366d67-4c83-46cf-a75b-6a953578b6f8@v12g2000vby.googlegroups.com> <445a602a-ca39-4806-88bf-be5820678d7f@gv8g2000vbb.googlegroups.com> |
On 06/20/11 05:06 PM, none wrote:
> Thanks, everyone... sorry it took so long to reply...
>
> Here's the code I came up with:
>
> class test {
> public:
>
>
> test (void) {
> pPointer = (char *) malloc (sizeof(char));
Two things:
why are you using malloc?
sizeof(char) is one by definition.
> }
>
> // Copy constructor
> test (const test& mytest) {
>
> pPointer = (char *) malloc (sizeof(char));
> *pPointer = *mytest.pPointer;
>
> }
>
> ~test () {
> free (pPointer);
> }
>
> test foo (void) {
> test myfoo;
> return myfoo;
> }
>
> // = operator overload
> test& operator= (const test& mytest) {
>
> *pPointer = *mytest.pPointer;
>
> return *this;
>
> }
>
> char* pPointer;
> };
>
> Is it correct? (if we suppose that for the purpose of this test
> pPointer will only point to a single char)
Well it won't leak or double free, but what do you really want to do?
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-07 03:16 -0700
Re: HEAP error when trying to use free() help needed "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-06-07 13:11 +0200
Re: HEAP error when trying to use free() help needed "Balog Pal" <pasa@lib.hu> - 2011-06-07 15:18 +0200
Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-07 19:50 +0200
Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-09 08:48 +0200
Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-08 11:11 +0200
Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-08 10:17 +0000
Re: HEAP error when trying to use free() help needed Mustansir <mustansir.azhar@gmail.com> - 2011-06-08 06:23 -0700
Re: HEAP error when trying to use free() help needed Krice <paulkp@mbnet.fi> - 2011-06-08 11:42 -0700
Re: HEAP error when trying to use free() help needed Pete Becker <pete@versatilecoding.com> - 2011-06-08 08:54 -1000
Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-19 22:06 -0700
Re: HEAP error when trying to use free() help needed Ian Collins <ian-news@hotmail.com> - 2011-06-20 17:17 +1200
Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-19 22:53 -0700
Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-20 06:06 +0000
Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-20 00:35 -0700
Re: HEAP error when trying to use free() help needed Ian Collins <ian-news@hotmail.com> - 2011-06-20 20:57 +1200
Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-20 18:25 +0000
csiph-web