Topic: default arguments


Author: mbmulder_remove_this_@home.nl ("Agent Mulder")
Date: Fri, 12 Sep 2003 23:01:33 +0000 (UTC)
Raw View
struct Room
{
public:
Room(bool a=true,bool b=true,bool c=true):Chair(a),Table(b),Bed(c){}
private:
bool Chair;
bool Table;
bool Bed;
};
int main()
{
Room bedroom; //chair, table, bed
Room study; //chair, table, bed
Room guestroom(,false,); //chair, no table, bed, no running water
Room living(,,false); //no bed in the living
Room toilet(,false,false); //no table, no bed
return 0;
}

The defective use of arguments above is a trivial case. I fill my
Windows structs in a function call and give a default value to each
formal argument. I want to apply a more elaborate use of default
arguments, but I am hindered by the fact that C++ does not allow
empty arguments.

Empty arguments would enable you to have one constructor or function
for whatever number and combination of arguments. You must only fill
in the non-default values and seperate them with the appropriate
number of comma's.

The semantics of this code is easily understood but the syntax is not
allowed in C++. The Annotated C++ Reference Manual:

<ARM 8.2.6>
It was felt that having empty arguments significant was not
only too subtle, but seriously decreased the opportunities
for detecting errors; an extra comma in an argument list is
not an unusual result of bad typing or sloppy editing.
</>

I don't agree on it being too subtle. It's only a matter of
counting comma's. I do feel a little offended however that the
language anticipates on my sloppy typing. There is a real need
for more flexible default arguments. The reasons not to have
them are not convincing enough.

-X



---
[ 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                       ]





Author: tilo@ethz.UUCP (Tilo Levante)
Date: 19 Sep 90 08:31:43 GMT
Raw View
I have the following problem/question:

given a function:
  int example (int i=2, int j=5);

Is there a way to call the funtion like:
  example (,3)

This would be very usefull for functions with a lot
of default parameters.

Tilo
tilo@nmr.lpc.ethz.ch