title: C++: How would one implement their own String class?
body: <p>I'm trying to re-learn C++ and was wondering if anyone could help me out here. I'm trying to implement my own String class to see if I can remember things, but I'm stuck on the constructor.</p>
  
  <p>I have my header file and want to have a constructor as so:</p>
  
  <p><b>Header File (MyFiles\String.h):</b></p>
  
  <pre><code>#ifndef STRING_
  #define STRING_
  
  using namespace std;
  #include &lt;iostream&gt;
  
  class String
  {
    private:
  
      static const unsigned int MAX = 32;    // Capacity of string
  
      char Mem[MAX];    // Memory to hold characters in string
      unsigned Len;     // Number of characters in string
  
    public:
  
      // Construct empty string
      //
      String()
      {
        Len = 0;
      }
  
      // Reset string to empty
      //
      void reset()
      {
        Len = 0;
      }
  
      // Return status information
      //
      bool empty() const
      {
        return Len == 0;
      }
  
      unsigned length() const
      {
        return Len;
      }
  
      // Return reference to element I
      //
      char&amp; operator[]( unsigned I )
      {
        return Mem[I];
      }
  
      // Return constant reference to element I
      //
      const char&amp; operator[]( unsigned I ) const
      {
        return Mem[I];
      }
  
      // Construct string by copying existing string
      //
      String( const String&amp; );
  
      // Construct string by copying array of characters
      //
      String( const char [] );
  
      // Copy string to the current string
      //
      String&amp; operator=( const String&amp; );
  
      // Append string to the current string
      //
      String&amp; operator+=( const String&amp; );
  };
  
  // Compare two strings
  //
  bool operator==( const String&amp;, const String&amp; );
  bool operator!=( const String&amp;, const String&amp; );
  
  // Put a string into an output stream
  //
  ostream&amp; operator&lt;&lt;( ostream&amp;, const String&amp; );
  
  #endif
  </code></pre>
  
  <p>The bit I'm stuck on is this:</p>
  
  <pre><code>String::String(const String&amp; str)
  {
      //what goes here?
  }
  </code></pre>
  
  <p>Thanks!</p>