## 18.3.5 Assignment Operators (cont.)

- Example: `String` class:

  >     String& String::operator=(const String& right)
  >     {
  >        if (this != &right)
  >        {
  >           delete[] buffer; // Get rid of old buffer
  >           len = right.length();
  >           buffer = new char[len + 1];
  >           for (int i = 0; i < len; i++)
  >              buffer[i] = right[i];
  >           buffer[len] = '\0';
  >        }
  >        return *this;
  >     }

prev |top |next