On Sat, Jul 14, 2012 at 07:04:07AM -0700, julien2412 wrote:
> Hello,
> 
> Keeping on slowly reading Bjarne Stroustrup's C++ book, I read that for =
> operator functions, we must delete/free the members before = assignment
> (which must copy).

Yes. Additionally, we must guard against self-assignment, because it
would lead to use of already deleted object. So, the canonical way to
write operator= is:

Foo& operator=(Foo const& other)
{
    if (this != &other)
    {
        // copy
    }
    return *this;
}

Or, if the class implements swap (and has accessible copy constructor,
which it should always have when it has operator=):

Foo& operator=(Foo const& other)
{
    Foo copy(other);
    swap(copy);
    return *this;
}

D.
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to