Topic: Defect report: Default modes missing from basic_fstream member


Author: petebecker@acm.org (Pete Becker)
Date: Sun, 4 Apr 2004 17:24:23 +0000 (UTC)
Raw View
Ben Hutchings wrote:
>
> [ Note: Forwarded to C++ Committee. -sdc ]
>
> The second parameters of the non-default constructor and of the open
> member function for basic_fstream, named "mode", are optional
> according to the class declaration in 27.8.1.11 [lib.fstream].  The
> specifications of these members in 27.8.1.12 [lib.fstream.cons] and
> 27.8.1.13 lib.fstream.members] disagree with this, though the
> constructor declaration has the "explicit" function-specifier implying
> that it is intended to be callable with one argument.
>

Well, sort of. The underlying notion is that you can't repeat a default
argument:

class C
{
public:
void f(int i = 3);
void g(int i = 3);
};

void C::f(int i = 3) // error
{
}

void C::g(int i) // correct: doesn't repeat default argument
{
}

The style adopted in the standard is to make class and template synopses
look pretty much like definitions, and for the detailed descriptions of
the functions to begin with declarations that look more like the actual
function definition. So the above class would be documented in the
standard like this:

1.1 Class C

class C
{
public:
void f(int i = 3);
void g(int i = 3);
};

1.1.1 C members

 void C::f(int i)

 (description goes here)

 void C::g(int i)

 (description goes here)

In small examples like this it's clear what's going on. In larger ones
(like basic_fstream) it's much easier to lose track of the default
arguments. On the other hand, repeating default arguments (or mentioning
them in the description) means that the same information is presented
twice, leading to the same kind of maintenance problems as having two
functions in your program that are supposed to do the same thing: it's
easy to change one and forget about the other.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]