I need to be sure that a constructor does not initialize some member variables:
struct A{
int a, b;
};
struct B: A{
int c;
B():c(42){}
}
char data[sizeof(B)];
B *v=reinterpret_cast<B*>(data);
v->a=42;
v->b=42;
new (v) B;
I want A to be defined in such a way that the placement new operator does not modify v->a
and v->b
. How should I do that?
A nasty hack would be to store the needed values of v->a
and v->b
in thread-local variables and then copying them in A::A()
. However this won't work if the constructor of B
creates another A
so I'll need a stack of them. Is there a faster way?