Strange behaviour with operator[]
<p>Having spent the last couple of days experimenting with C++ operator[] methods, I've come across an anomaly that I can't easily explain. The code below implements a simple test string class, which allows the user to access single characters via its subscript "operator" method. As I would like to differentiate between lvalue and rvalue subscript contexts, the "operator" method returns an instance of the custom "CReference" class as opposed to a standard C++ character reference. Whilst the "CReference" "operator char()" and "operator=(char)" methods appear to handle each rvalue  and lvalue context respectively, g++ refuses to compile without the presence of an additional "operator=(CReference&amp;)" method as documented below. Whilst the addition of this method appears to placate some kind of compile-time dependency, it is never actually invoked at run-time during the execution of the program.</p>

<p>As someone who thought they had acquired a fundamental understanding of C++ intricacies, this project has certainly proved to be a humbling experience. If anyone could see their way to enlightening me as to what's going on here, I would be eternally grateful. In the meantime, I'm going to have to pull out the C++ books in order to reconcile the void** between what I know and what I think know.</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

// Class for holding a reference to type char, retuned by the "operator[](int)"
// method of class "TestString". Independent methods permit differentiation
// between lvalue and rvalue contexts.
class CReference
{
 private:
   char&amp; m_characterReference;

 public:
   // Construct CReference from char&amp;
   CReference(char&amp; m_initialiser)
     : m_characterReference(m_initialiser) {}

   // Invoked when object is referenced in a rvalue char context.
   operator char()
   {
    return m_characterReference;
   }

   // Invoked when object is referenced in a lvalue char= context.
   char operator=(char c)
   {
    m_characterReference = c;
    return c;
   }

   // NEVER INVOKED, but will not compile without! WHY???
   void operator=(CReference &amp;p_assignator){}
};


// Simple string class which permits the manipulation of single characters
// via its "operator[](int)" method.
class TestString
{
 private:
   char m_content[23];

 public:
   // Construct string with test content.
   TestString()
   {
    strcpy(m_content, "This is a test object.");
   }

   // Return pointer to content.
   operator const char*()
   {
    m_content[22] = 0;
    return m_content;
   }

   // Return reference to indexed character.
   CReference operator[](int index)
   {
    return m_content[index];
   }
};


int main(int argc, char *argv[])
{
 TestString s1;

 // Test both lvalue and rvalue subscript access.
 s1[0] = s1[1]; 

 // Print test string.
 printf("%s\n", (const char*)s1);
 return 0;
}
</code></pre>
