Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unnamed objects.

1 view
Skip to first unread message

Stephen J. Muir

unread,
Nov 7, 1986, 3:20:32 PM11/7/86
to
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: ste...@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

0 new messages