TITLE: Lifetimes of temporaries RESPONSE: jamshid@ses.com (Jamshid Afshar), 12 Jul 94 SCursorPush is a handy class for changing the cursor during the execution of a block of code: void calc() { //... if (ready) { SCursorPush dummy(g_pauseCurs); // do some time-consuming task } //... } The SCursorPush constructor saves the original cursor shape and changes it to the pause bitmap(?). The destructor for `dummy', which is called at the `if' block's closing brace, changes the cursor back to the original shape. The following code, from tprojecteditor.cc, creates an "unnamed" temporary SCursorPush object. if(retVal != dbrsOK) { SCursorPush(g_pauseCurs); MCreateCallback mcb ; gDataBase->create(dbName,&mcb); return TRUE; } Compilers are free to destroy that temporary object whenever it wants (up to the end of the enclosing block). Cfront happens to wait until the end of the block, so the code works as expected, but other compilers (like g++) would destroy it immediately, causing the cursor to flash back to the original shape before gDataBase->create() is called. Furthermore, ANSI/ISO will most likely end up *requiring* the compiler to destroy such temporaries at the end of the statement in which they were created (meaning Cfront compilers will have to be modified). So, make sure you name objects if you want them to hang around during the entire execution of a block of code: if(retVal != dbrsOK) { SCursorPush dummy(g_pauseCurs); MCreateCallback mcb ; gDataBase->create(dbName,&mcb); return TRUE; }