In error: use of deleted function an error is explained, but it is not explained how to resolve the error. Consider the following c++ code.
struct foo{ int& i; }; int main() { int i = 0, j = 1; foo v = {i}; v = {j}; return 0; } This results in error: use of deleted function ‘foo& foo::operator=(foo&&)’ referring to v = {j};. This can be resolved as follows.
struct foo{ int& i; }; int main() { int i = 0, j = 1; foo v = {i}; foo v2 = {j}; return 0; } But this is ridiculous. I don't want to declare a new variable, I just want to get rid of the old instance of v and assign it a new value. Is there really no way to simply redefine v?
iwith a reference to a temporary, a disaster.int& iintostd::reference_wrapper<int> i.jwould stay valid.