$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] How to create a shallow copy without calling a constructor?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-01-02 14:03:01
vicente.botet wrote:
> I have tried with
> 
> class C {
> public:
>   C* shallow_clone() {
>      C* p = reinterpret_cast<C>(malloc(sizeof(C));
>       if (p==0) {
>           throw std::bad_alloc();
>       }
>       memcpy(p, this, sizeof(C));
>       return p;
>   }
> };
Or, maybe more appropriate,
C* shallow_clone() {
   C* p = static_cast<C*>(::operator new(sizeof(C)));
   memcpy(p, this, sizeof(C));
   return p;
}