Assignment operator with reference members

It’s syntactically correct. If the placement new throws, however, you
end up with an object you can’t destruct. Not to mention the disaster
if someone derives from your class. Just don’t do it.

The solution is simple: if the class needs to support assignment, don’t
use any reference members. I have a lot of classes which take reference
arguments, but store them as pointers, just so the class can support
assignment. Something like:

struct A
{
    int* myRef;
    A( int& ref ) : myRef( &ref ) {}
    // ...
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)