I\'m using a C++ base class and subclasses (let\'s call them A and B for the sake of clarity) in my embedded system.
It\'s time- and space-critical, so I really nee
You can poison operator new
in just the same way as you can a copy constructor. Just be sure not to poison placement new. A virtual destructor would still be a fine recommendation.
int main() {
char data[sizeof(Derived)];
if (condition)
new (data) Derived();
else
new (data) Base();
Base* ptr = reinterpret_cast (&data[0]);
ptr->~Base();
}