
2 Jan
2010
2 Jan
'10
7:03 p.m.
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; }