title: overload array operator for mystring class
body: <p>I need help figuring out how to overload the array operator for a <code>MyString</code> class that I have to create. I already have everything else figured out, but the arrays are giving me trouble, for some reason.</p>
  <p>Here is my header file:</p>
  <pre class="lang-cpp prettyprint-override"><code>#ifndef MYSTRING_H
  #define MYSTRING_H
  
  #include &lt;iostream&gt;
  #include &lt;cstring&gt;  // For string library functions
  #include &lt;cstdlib&gt;  // For exit() function
  using namespace std;
  
  // MyString class: An abstract data type for handling strings
  class MyString
  {
  private:
      char *str;
      int len;
  public:
      // Default constructor.
      MyString()
      { 
          str = 0; 
          len = 0;
      }
       
      // Convert and copy constructors. 
      MyString(char *);
      MyString(MyString &amp;);
      
      // Destructor. 
      ~MyString()
      { 
          if (len != 0)
              delete [] str;
          str = 0;
          len = 0;
      }
       
      // Various member functions and operators.   
      int length() { return len; }
      char *getValue() { return str; };
      MyString operator+=(MyString &amp;);
      MyString operator+=(const char *);
      MyString operator=(MyString &amp;);
      MyString operator=(const char *);
      bool operator==(MyString &amp;);
      bool operator==(const char *);
      bool operator!=(MyString &amp;);
      bool operator!=(const char *);
      bool operator&gt;(MyString &amp;);
      bool operator&gt;(const char *);
      bool operator&lt;(MyString &amp;);
      bool operator&lt;(const char *);
      bool operator&gt;=(MyString &amp;);
      bool operator&gt;=(const char*);
      bool operator&lt;=(MyString &amp;);
      bool operator&lt;=(const char *);
      MyString operator [](MyString *);
      
      // Overload insertion and extraction operators.
      friend ostream &amp;operator&lt;&lt;(ostream &amp;, MyString &amp;);
      friend istream &amp;operator&gt;&gt;(istream &amp;, MyString &amp;);
  };
  #endif
  </code></pre>
  <p>What would the body look like for <code>MyString::operator []</code>?</p>
  <pre class="lang-cpp prettyprint-override"><code>MyString MyString::operator [](MyString *)
  {
      ... what goes here
  }
  </code></pre>