Subject: Re: [boost] How to create a shallow copy without calling aconstructor?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-01-04 14:13:13
Am Saturday 02 January 2010 23:34:51 schrieb vicente.botet:
> Derived* p = reinterpret_cast<Derived*>( new char[sizeof(Derived)]);
> std::memcpy(p, static_cast<Derived const*>(this), sizeof(Derived));
> return p;
quick question about this, is it legal to do the following?
T *t=reinterpret_cast<T *>(new char[sizeof(T)]);
new (&t) T;
Boost.Serialization must use that, as it passes unconstructed memory to
load_construct_data but lets the user "delete" the object, so I figure it
must be ok. am I right?
my platform (with valgrind) doesn't have a problem with it, but is it defined
to be ok or portable among all known platforms?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk