## 18.3.1 Constructors with Arguments

- All constructors perform necessary initialization
- Example: Our c'tor must allocate space from heap and initialize:

  >     String::String(const char p[])
  >     {
  >        // Determine number of characters in string (strlen(p))
  >        len = 0;
  >        while (p[len] != '\0')
  >           len++;
  >        // Allocate buffer array, remember to make space for NULL character
  >        buffer = new char[len + 1];
  >        // Copy new characters (strcpy( buffer, p ))
  >        for (int i = 0; i < len; i++)
  >           buffer[i] = p[i];
  >        buffer[len] ='\0';
  >     }

  > (Operators as described in chptr. 17)

prev |top |next