- // NB: must first add reference to "other", since other might be *this.
- other.p->add_reference();
+ // NB1: Must first add reference to "other", since other might be *this.
+ // NB2: Cache other.p, because if "other" is a subexpression of p,
+ // deleting p will also invalidate "other".
+ T *otherp = other.p;
+ otherp->add_reference();