title: Overloading Bitwise And(&) Operator and "*this" in Class Functions
body: <p>I have several questions about this particular piece of code. I should first mention that <code>pChar</code> will always be a dynamic character array that is resized when needed by methods I have not listed.  I have scoured my reference manual and this website but cannot seem to gain a clear understanding of how the &amp; operator works in full.  I also do not want to use an alternative as this is an assignment and am not allowed to.  I've been at this for days so any help would be appreciated.</p>
  
  <ol>
  <li><p>What exactly is <code>*this</code> pointing to when using the &amp; operator?
    I have been assuming it points to the left operand.</p></li>
  <li><p>If this is not the case, how do I access the left operand within the &amp; operator method?</p></li>
  <li><p>If this is all completely incorrect, how can I reach the desired outcome by using the overloaded <code>operator&amp;</code>?</p></li>
  </ol>
  
  <p>Method for &amp; operator:</p>
  
  <pre><code>PDS_String &amp; PDS_String::operator &amp; (const PDS_String &amp; Str)const
  {
       PDS_String temp(*this);
       strcat(temp.pChar, Str.pChar);
       return temp;
  }
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>void main ()
  {
          PDS_String String1;
          PDS_String String2;
          PDS_String String3;
  
          String1 = "monkey";
          String2 = "chicken";
          String3 = String1 &amp; String2;  
  // Desired outcome for String3 is "monkeychicken"
  }
  </code></pre>
  
  <p>Class:</p>
  
  <pre><code>class PDS_String
  {
  public:
      PDS_String();                       //Default
      PDS_String(const PDS_String &amp;);     //Copy
      ~PDS_String();                      //Destructor
  
      char *          operator &amp;   (const PDS_String &amp;) const;  // Concatenation
      PDS_String &amp;    operator =   (const char *);    // Assignment
  
  // I haven't listed all methods and operator overloads
  
  private:
      char *      pChar;
      long        NumChars;
      long        NumSlots;
  };
  </code></pre>
  
  <p>Assignment operator method:</p>
  
  <pre><code>    PDS_String &amp; PDS_String::operator = (const char * Str)
      {
          if (pChar == Str)
              return *this;
          else
          {
              if (NumSlots &lt; strlen(Str))
              {
                  delete[] pChar;
                  pChar = new char[(strlen(Str) + 1)];
                  NumSlots = (strlen(Str));
              }
              else;
          }
          strcpy(pChar, Str);
          NumChars = strlen(Str);
           return *this;
      }
  </code></pre>
  
  <p>Thank you very much Matt McNabb.  I have changed the operator&amp; method to reflect your suggestion:</p>
  
  <pre><code>char * PDS_String::operator &amp; (const PDS_String &amp; Str)const
  {
       char * temp;
       temp = new char[strlen(pChar)+strlen(Str.pChar)+1];
       temp = pChar;
       strcat(pChar, Str.pChar);
       return temp;
  }
  </code></pre>