In the C++ code below, am I guaranteed that the ~obj() destructor will be called after the // More code executes? Or is the compiler allowed to destruct the
The destructor will not be called until the object goes out of scope.
The C++ faq lite has a good section on dtors
You are OK with this - it's a very commonly used pattern in C++ programming. From the C++ Standard section 12.4/10, referring to when a destructor is called:
for a constructed object with automatic storage duration when the block in which the object is created exits