title: Syntax for Overloading Type Conversion Operator
body: <p>I'm sorry if this has been asked already, but I'm still learning C++ and struggling with a bit of syntax.</p>
  
  <p>I'm supposed to overload the type conversion operator, so that it will accept an object and return an int value, based on a protected int inside that object.</p>
  
  <p>Header file:</p>
  
  <pre><code>definitions.h
  
  class Baseballs 
  {
  protected:
      int currentValue;
  public:
      Baseballs(int);
      int operator= (Baseballs&amp;); // ??????
  }
  </code></pre>
  
  <p>Methods:</p>
  
  <pre><code>methods.cpp
  
  #include "definitions.h"
  
  Baseballs::Baseballs(int value)
      {
      currentValue = value;
      }
  
  int Baseballs::operator=(Baseballs &amp;obj) // ??????
      { 
          int temp = obj.currentValue;
          return temp; 
      } 
  </code></pre>
  
  <p>So in main.cpp, if I create an object:</p>
  
  <pre><code>Baseballs order(500);
  </code></pre>
  
  <p>Then 500 is assigned to <code>currentValue</code>.  I need to be able to assign that to an int variable, and ultimately print it for verification, such as:</p>
  
  <pre><code>int n = order;
  cout &lt;&lt; n;
  </code></pre>
  
  <p>What I'm having trouble with is the syntax for overloading <code>=</code>.  Can someone tell me what the proper syntax for the definition and method should be?</p>