Article View: net.lang.c++
Article #382Unnamed objects.
From: Stephen J. Muir
Date: Fri, 07 Nov 1986 20:20
Date: Fri, 07 Nov 1986 20:20
27 lines
1357 bytes
1357 bytes
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
Technical Details
Message-ID:
<636@comp.lancs.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephenShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!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