Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephen From: stephen@comp.lancs.ac.uk (Stephen J. Muir) Newsgroups: net.lang.c++ Subject: Unnamed objects. Message-ID: <636@comp.lancs.ac.uk> Date: Fri, 7-Nov-86 15:20:32 EST Article-I.D.: comp.636 Posted: Fri Nov 7 15:20:32 1986 Date-Received: Sun, 9-Nov-86 03:05:05 EST Reply-To: stephen@comp.lancs.ac.uk (Stephen J. Muir) Distribution: world Organization: Department of Computing at Lancaster University, UK. Lines: 27 I have defined a type to close a file automatically when it goes out of scope: class auto_close { int stored_fd; public: auto_close (int fd) { stored_fd = fd; } ~auto_close () { int e = errno; close (stored_fd); errno = e; } }; Now, after opening a file: fd = open ("file", 0) I declare one of these: auto_close my_close (fd); The only problem is I have to think up a name (my_close) which I never use. Is there any way to get away with not having to think up a name? If there isn't, I think there should be! BSD 4.2, VAX-11/750, C++ 1.1. -- EMAIL: stephen@comp.lancs.ac.uk | Post: University of Lancaster, UUCP: ...!mcvax!ukc!dcl-cs!stephen | Department of Computing, Phone: +44 524 65201 Ext. 4120 | Bailrigg, Lancaster, UK. Project:Alvey ECLIPSE Distribution | LA1 4YR