Mauricio Gomes wrote:
I would create a class (File or other name) that close() on its destructor.
I do not like this solution, but not because it doesn't work. It works just fine, and probably better than the more complicated alternatives that I have been thinking of. The trouble is that its 'difficult.' Writing a class to do this takes a small but significant amount of effort. Maintaining code with this class be be slightly but significantly more difficult. In particular, in code specific to a particular problem domain (as opposed to in general-purpose libraries), I don't like to see a whole lot of code that has nothing to do with that domain, or adds a whole lot of structure for very little expressive benefit. This sort of verbosity is a problem--I think--and a particular problem for C++. A significant criticism of C++ that I have heard is that the implementation of many sorts of code requires too structure, so that there is less actual expressive code than non-expressive code. Aaron W. LaFramboise