Listing 3 This code is an explicit copy constructor that replicates the entire array. It performs a "deep copy" — it copies the entire substructure of the object.

#include <iostream.h>
#include <string.h>

class String
   {
   ...
public:
   String(const String &s);
   ...
private:
   size_t len;
   char *str;
   };

String::String(const String &s)
   {
   len = s.len;
   str = new char[len + 1];
   strcpy(str, s.str);
   }
// End of File