devxlogo

The Order of Local Objects’ Destruction

The Order of Local Objects’ Destruction

On exit from a scope, destructors are called for all local automatic objects that are declared in that scope, in the reverse order of their declaration. For example:

   void f()  {    CmyClass obj1;  // 1    CmyClass obj2;  // 2   }

obj1 is constructed before obj2. On exit from f(), the objects are destroyed in the reverse order of their declaration, so obj2 will be destroyed before obj1.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist