title: C++ Instantiating "Implicit" Class Object
body: <pre><code>class Cents
  {
  private:
  int m_nCents;
  
  public:
  Cents(int nCents) { m_nCents = nCents; }
  
  // Overload cCents + int
  friend Cents operator+(const Cents &amp;cCents, int nCents);
  int GetCents() { return m_nCents; }
  };
  
  // note: this function is not a member function!
  Cents operator+(const Cents &amp;cCents, int nCents)
  {
  return Cents(cCents.m_nCents + nCents);
  }
  
  int main()
  {
  Cents c1 = Cents(4) + 6;
  std::cout &lt;&lt; "I have " &lt;&lt; c1.GetCents() &lt;&lt; " cents." &lt;&lt; std::endl;
  
  return 0;
  }
  </code></pre>
  
  <p>It's not clear to me how the expression</p>
  
  <pre><code>Cents(4)+6 
  </code></pre>
  
  <p>in line</p>
  
  <pre><code>Cents c1 = Cents(4) + 6;
  </code></pre>
  
  <p>is evaluated.
  Yeah I know that we're overloading operator "+" for operands of types Cents and int respectively.</p>
  
  <p>As I understand Censt(4) is the constructor, right? So when</p>
  
  <pre><code>Cents operator+(const Cents &amp;cCents, int nCents)
   {
   return Cents(cCents.m_nCents + nCents);
   }
  </code></pre>
  
  <p>is called does cCenst become a reference to Cents(4)?</p>
  
  <p>From the line</p>
  
  <pre><code>return Cents(cCents.m_nCents + nCents);
  </code></pre>
  
  <p>one can deduce that cCenst is an object of type Censt since we access m_nCents via member selection operator "." But Censt(4) is a constructor and not a class object.</p>
  
  <p>To me it doesn't seem to make sense for cCenst to be a reference to Cents(4) since they're not equivalent.</p>