title: Why in C++ Local Object doesn't free after the function terminated?
body: <pre><code>class MyClass 
  {
  private:
      int color;
      string name;
  public:
      MyClass(int co, string n) :
              name(n), color(co) 
      {
          cout &lt;&lt; "MyClass created" &lt;&lt; endl;
      }
      ~MyClass() 
      {
          cout &lt;&lt; "MyClass is deleted" &lt;&lt; endl;
      }
      string getName() 
      {
          return this-&gt;name;
      }
  };
  
  
  MyClass func() 
  {
      MyClass c(0, "test");
      return c;
  }
  
  int main() 
  {
      MyClass cls = func();
     cout &lt;&lt; cls.getName() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>And the output:</p>
  
  <pre><code>MyClass created
  test
  MyClass is deleted
  </code></pre>
  
  <p>Hello, I know that in C it's impossible to get an address of local variable from function calls ( i.e  - it's impossible to  initaialize on the stack an array of int by calling another function and returns it) .</p>
  
  <p>I noticed that in C++ something is different; 
  I created an instance of some object without use the operator <code>new</code>, outside the main function, then returns it to the main function and it's like I initizalized in the main. May someone can explain why the address of object's instance didn't free after the function which created it terminated?</p>
  
  <p>(I expected that MyClass instance deleted when func terminated - No "test" on the output)</p>
  
  <p>thanking you in advance </p>