title: C++: Returning an object and assigning it to a function
body: <p>I am an beginner in C++ and would like to do something like this: </p>
  
  <pre><code>myObj f(){
      // do stuff 
      // return instance of myObj
  }
  
  int main(){
      // do stuff
      myObj mO = f(); 
  }
  </code></pre>
  
  <p><strong>What would I have to do, to make this work in C++?</strong></p>
  
  <p>My thoughts were, that I would have to implement an assign operator for the myObj stuct/class or to write another constructor that looks like this <code>myObj::myObj(myObj mO){...}</code>, which I use like this <code>myObj = myObj(f());</code>. </p>
  
  <p>Is this correct? </p>
  
  <p>Do I have to do more, to make this work? </p>
  
  <p>Could you maybe provide a working example? </p>
  
  <p>Thanks!</p>