[net.lang.c++] Unnamed objects.

stephen@comp.lancs.ac.uk (Stephen J. Muir) (11/07/86)

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