title: how does C++ operator ++ overloading work
body: <p>I am currently practicing operator overloading regarding the increment operator ++, so I want to create a class myInt with just an integer m_Int and initialize it to zero.To distinguish pre &amp; post increment, I created two overloading functions like below:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class myInt 
  {
      friend ostream &amp; operator&lt;&lt;(ostream &amp;cout, myInt &amp;i);
      friend myInt &amp; operator++(myInt &amp;i);
  public:
      myInt() 
      {
          m_Int = 0;
      }
      // post increment
      myInt operator++() 
      {
          myInt temp = *this;
          m_Int++;
          return temp;
      }
  private:
      int m_Int;
  };
  
  ostream &amp; operator&lt;&lt;(ostream &amp;cout, myInt &amp;i) 
  {
      cout &lt;&lt; &quot;i.m_Int = &quot; &lt;&lt; i.m_Int;
      return cout;
  }
  // pre increment
  myInt &amp; operator++(myInt &amp;i) 
  {
      i.m_Int += 1;
      return i;
  }
  void test() 
  {
      myInt int1;
      cout &lt;&lt; int1 &lt;&lt; endl;       // output ought to be 0 here
      cout &lt;&lt; ++int1 &lt;&lt; endl;     // having 1 here for prefix increment 
      cout &lt;&lt; int1++ &lt;&lt; endl;     // still 1 since its postfix increment
      cout &lt;&lt; int1 &lt;&lt; endl;       // 2 here thanks to postfix increment
  }
  int main() 
  {
      test();
      system(&quot;pause&quot;);
      return 0;
  }
  </code></pre>
  <p>So above is what I had in mind, based on my understanding, ++int1 == operator++(int1), and int1++ == int1.operator++(), so I choose to put one function inside the class, and another outside. But I got an error saying multiple functions matched both ++int1 and int1++, but these two do have different parameters, is it because one is defined inside the class and the other one is not, so parameter (myInt &amp;i) doesn't make a difference here?
  Anyone has a clue if I got &quot;++int1 == operator++(int1), and int1++ == int1.operator++()&quot; part wrong? and how should I fix this to make it work? Much appreciated!</p>