Order and point of calling destructor
Lets say I have two local objects. When the function returns, is it guaranteed which one will go out of the scope first? For example: I have a class like this: class MutexLock { /* Automatic unlocking when MutexLock leaves a scope */ public: MutexLock (Mutex &m) { M.lock(); } ~MutexLock(Mutex &m) { M.unlock(); } }; This is a very common trick used to automatically release the mutex when going out of scope. But what if I need two mutexes in the scope? void *func(void *arg) { MutexLock m1; MutexLock m2; do_work(); } // m1 and m2 will get unlocked here. But in what order? m1 first or m2 first?