## 18.3.3 Copy Constructors (cont.)

- Example: each `String` has its own dynamically allocated buffer, so default behavior is insufficient. We extend this behavior:

  >     String::String(const String& right)
  >     {
  >        int n = right.length();
  >        buffer = new char[n + 1];
  >        for (int i = 0; i < n; i++)
  >           buffer[i] = right[i];
  >        buffer[n] = '\0';
  >     }

prev |top |next