title: C++ pass-by-value with non-primitive types?
body: <p>I must have a fundamental misunderstanding about C++11.  My professors told me it wasn't possible to pass a non-primitive type to a function except by reference or pointer.  However, the following code works just fine</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class MyClass
  {
  public: 
      int field1;
  };
  
  void print_string(string s) { 
      cout &lt;&lt; s &lt;&lt; endl; 
  }
  
  void print_myclass(MyClass c) { 
      cout &lt;&lt; c.field1 &lt;&lt; endl; 
  }
  
  int main(int argc, char *argv[]) 
  {
      string mystr("this is my string"); 
      print_string(mystr); // works
      MyClass m; 
      m.field1=9; 
      print_myclass(m); 
      return 0;
  }
  </code></pre>
  
  <p>Running the program yields the following output</p>
  
  <pre><code>this is my string
  9
  
  RUN SUCCESSFUL (total time: 67ms)
  </code></pre>
  
  <p>I'm using MinGW/g++ on Win7</p>
  
  <p>Why does that work?  I thought non-primitive types couldn't be passed by value?!</p>