Connecting Tech Pros Worldwide Help | Site Map

using placement new to re-initialize part of an object

removeps-generic@yahoo.com
Guest
 
Posts: n/a
#1: Apr 4 '06
Hi. I'm using placement new to re-initialize part of an object. Is
this OK?

struct BaseImp
{
All& r_all;
BaseImp(All& all) : r_all(all)
};

struct Calc::Imp : public BaseImp
{
int d_x;
Imp(All& all, int x) : BaseImp(all), d_x(x) { }
}

void Calc::somefunction(All& newall)
{
assert(typeid(*d_imp) == typeid(Imp));
new (d_imp) BaseImp(newall);
}

This way, d_imp->d_x is unchanged, but d_imp->r_all is changed.

What does the standard say about this?

Thanks.

Closed Thread