title: Implicit conversion from user-defined type to primitive type in C++
body: <p>I am able to find plenty of information about implicit conversion from, say, an int to a user defined type.  i.e. if a constructor takes an int as its parameter and is not prefaced by "explicit" then implicit conversions can occur.</p>
  
  <p>What if I want my class to implicitly convert <em>to</em> an int?</p>
  
  <p>For example, what function needs to be added either inside or outside of SimpleClass such that the main function will compile and output "1" to the console? (see comments)</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class SimpleClass
  {
  private:
      int m_int;
  public:
      SimpleClass(int value)
      : m_int(value) {}
  };
  
  int main(int argc, const char * argv[])
  {
      SimpleClass simpleclass(1);
      int i = simpleclass; // does not complile
      std::cout &lt;&lt; i &lt;&lt; std::endl; // should output "1" to the console
      return 0;
  }
  </code></pre>