Ted:

Good comments on copy ctors.

> Having a copy ctor and no
> operator=() is almost always an error.  (Actually implementing an
> operator= is a bit tricky as it must deal properly with self-assignment.)

We've had a few bugs because copy ctor and operator=() didn't agree,
usually because one was updated but the other wasn't.  I don't think we
have any situations where they shouldn't completely agree.

One way to make them always agree is to have operator=() use explicit dtor
and placement new.  Then any change to the copy ctor is automatically
shared.  This recipe only requires replacing Classname:

    Classname& operator=(const Classname& other)
    {
      if (this != &other) {
        this->~Classname();
        new(this) Classname(other);
      }
      return *this;
    }

Caveat: It's not meant for base classes.

        Tom Breton (Tehom)



------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Rosegarden-devel mailing list
[email protected] - use the link below to unsubscribe
https://lists.sourceforge.net/lists/listinfo/rosegarden-devel

Reply via email to