title: How to return a value when a class instance is referenced in c++
body: <p>Is it possible to return a value when referencing (not sure it's the correct term) an instance of a class?
  For example:</p>
  <pre class="lang-cpp prettyprint-override"><code>class A {
  
  };
  
  int main() {
      A instance;
      int val = instance; // how can I make this return a int for example?
  }
  </code></pre>
  <p>I'm pretty sure this is possible as it works with <code>std::string</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>std::string s = &quot;ABC&quot;;
  std::cout &lt;&lt; s; // prints 'ABC'.
  </code></pre>