G
Giancarlo Niccolai
Hello all.
I have peeked through the FAQ and all relevant links, and also through
Stroustrup book, but I have not been able to find an answer, so I have to
post here as a last resort.
It makes sense that if you have virtual destructors, they are eventually
used in the explicit destructor call when using the placement new semantic:
class A {
....
virtual ~A() { cout <<"one" <<endl; }
};
class B: public A {
....
virtual ~B() { cout << "two" << endl; }
};
....
A *mem = static_cast<A*>(new( good_memory ) B);
// Now we have a B item in a placed good memory, which is pointed
// by a base class A*
Now, using the semantic
mem->~A();
free_good_memory( mem );
won't do, as it won't scan the B object Vtable and will just feed the mem
object in the A class destructor.
The question is: how to use virtual destructors when dealing with placed
memory?
TIA,
Giancarlo Niccolai
I have peeked through the FAQ and all relevant links, and also through
Stroustrup book, but I have not been able to find an answer, so I have to
post here as a last resort.
It makes sense that if you have virtual destructors, they are eventually
used in the explicit destructor call when using the placement new semantic:
class A {
....
virtual ~A() { cout <<"one" <<endl; }
};
class B: public A {
....
virtual ~B() { cout << "two" << endl; }
};
....
A *mem = static_cast<A*>(new( good_memory ) B);
// Now we have a B item in a placed good memory, which is pointed
// by a base class A*
Now, using the semantic
mem->~A();
free_good_memory( mem );
won't do, as it won't scan the B object Vtable and will just feed the mem
object in the A class destructor.
The question is: how to use virtual destructors when dealing with placed
memory?
TIA,
Giancarlo Niccolai