#include <new>
struct House { };
struct Room
{
House& h;
Room(House& h) : h(h) { }
};
int main()
{
House h1;
House h2;
Room r(h1);
//r = Room(h2); // This obviously won't work.
///
r.~Room();
new(&r) Room(h2); // This does work
}
I have used a reference member in one place in my project and I'm wondering it's safe to use this trick as a way to reinitialize the object with a different reference.