From -5234274741359695430
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,64409d9769f709f0
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,64409d9769f709f0
X-Google-Attributes: gidf78e5,public
From: James Kuyper <kuyper@wizard.net>
Subject: Re: Is this legal C++?
Date: 1998/08/10
Message-ID: <35CF0E1E.2781@wizard.net>#1/1
X-Deja-AN: 379735290
X-NNTP-Posting-Host: gscsgi02.gsfc.nasa.gov
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <01bdc100$f82d21b0$19011a12@bwing> <01bdc170$c51f6970$17031712@dialup-337> <35CA1929.64D06555@acm.org> <35CA2B19.15FB@wizard.net> <35CB8677.ADAED7F1@acm.org> <01bdc328$abd6a140$182510ac@superstition>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
Mime-Version: 1.0
Newsgroups: comp.lang.c++,comp.std.c++
Originator: clamage@taumet


Jason Hunter wrote:
> 
> Pete Becker and James Kuyper
> 
> > The question wasn't about how to convert uninitialized memory to an
> > object, but how to reinitialize an object that has already been
> > constructed (although apparently incorrectly). That sounds like a silly

Hey! The quoted text is entirely Pete's; I don't deserve any credit for
it. He's right - what I suggested is entirely inappropriate for that
context.

> Actually, you could still use the placement operator new trick even to
> reinitialize an already created object. ...

True.

> ...  Just case the object pointer to
> void * and then pass it to the new operator. ...

Wrong. If the object has actually been constructed, it must be destroyed
before you reconstruct it.

>... This is what I have done.
> thanks a lot James for the suggestion.  Now that my problem is solved, the

No! No! No! Don't credit me with that!. What I said applied only for
unitialized memory. The dangerous but legal way to re-construct
initialized memory is to explicitly call the destructor, then call
placement new(). Don't do this unless you know exactly what you are
doing. In particular, make sure you understand exactly what the
consequences are with regard to multiple and virtual inheritance. (I'm
not sure what they are, but I remember that those were issues that
someone brought up when I first saw this technique discussed).


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




