Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!zephyr.ens.tek.com!uw-beaver!fluke!dyndata!dan From: dan@dyndata.UUCP (Dan Everhart) Newsgroups: comp.lang.c++ Subject: anonymous variables Message-ID: <351@dyndata.UUCP> Date: 3 May 90 03:36:34 GMT Organization: Dynamic Data & Electronics, Edmonds WA Lines: 35 Speaking of non-sequiturs.... It might be neat to be able to define objects anonymously, that is, if you wrote Xyz; an instance of class Xyz with no name would be created. Why? If the object was created only for the side effects caused by the constructor and destructor. For example, here's a way to implement critical sections: class Critical { Critical () { ShutOffInterrupts (); }; ~Critical () { TurnOnInterrupts (); }; }; If you didn't have to name objects you could just say { Critical; ... // Stuff in here runs with interrupts disabled. } // Interrupts snap back on when the block is exited. Of course you can just put in any old name for the object and it will work. But why bother if there is never a reference to the object? No doubt somebody is going to suggest naming the object "section" in the above example. Oops, I just did.