title: Destructor when is this object out of scope
body: <pre><code>class Entity {
      //attributes
  public:
      float X, Y;
      Entity() {
          X = 0;
          Y = 0;
          cout &lt;&lt; &quot;Created Entity!&quot; &lt;&lt; endl;
      }
      ~Entity() {
          cout &lt;&lt; &quot;Entity Destroyed!&quot; &lt;&lt; endl;
      }
      void Print() {
          cout &lt;&lt; X &lt;&lt; &quot;, &quot; &lt;&lt; Y &lt;&lt; endl;
  }
  
  
  
  
  };
  void func() {
      Entity e;
      e.Print();
      
  }
  int main()
  {
      func();
      cout &lt;&lt; &quot;b&quot;;
  }
  </code></pre>
  <p>So I'm kinda having trouble understanding what exactly is happening here, I don't understand when and how e is out of scope. func creates e and then calls the method function but all that only gets executed when I call func in main right? So only when I call func in main e gets created and the method gets called but how exactly is it ever out of scope?</p>
  <p>Like can someone please try to explain this like I'm a 5 year old? The entity only gets created when func gets called in main right? When could e ever be out of scope?</p>