🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Stephen J. Muir Fri, 07 Nov 1986 20:20
Unnamed objects.
#382
Author: Stephen J. Muir
Date: Fri, 07 Nov 1986 20:20
27 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads