Is it okay to use placement new
for automatic objects? Please consider the following example:
class Button
{
public:
Button() { }
virtual ~Button() { }
// and a lot of members
};
class Screen
{
public:
Screen() { }
virtual ~Screen() { }
Button submit_btt;
void doStuff()
{
// ...
submit_btt.~Button();
new(&submit_btt) Button();
//...
}
// and a lot of members
};
void process(void)
{
Screen myObj;
//...
myObj.doStuff();
//...
}
This pseudo code represent situation which has been met when working GUI framework.
What are your thought about this code? Are there any insecurities? What can go wrong?
Will myObj
and its' members be properly destroyed (all member destructors called and all other operations) after process()
function?