Community wiki, because this almost certainly invokes UB.
If you have a copy constructor you can make an assignment operator using placement new:
struct Transaction {
Transaction(Book& bb, Patron& pp, Date dd)
: b(bb), p(pp), d(dd) { }
Transaction(const Transaction & src)
: b(src.b), p(src.p), d(src.d) { }
Transaction & operator= (const Transaction & src) {
if (this != &src) {
this->~Transaction();
Foo * copy = new (this) Transaction(src);
return *copy;
} else {
return *this;
}
}
Book& b;
Patron& p
Date d;
};
This might work with your computer, with your compiler, with a specific optimization setting. Then again, it might not. Or it might suddenly stop working when your operator system auto-updates the C++ ABI library. Or it might suddenly stop working when you deliver it to your customer who has a slightly different version of the C++ ABI library.
No matter how you cut it, changing a reference is undefined behavior.