Re: default parameter value
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 11/03/03
- Next message: redgryphon_at_shaw.ca: "Condos in Canada @ 75 cents on the US Dollar!"
- Previous message: Frank Schmitt: "Re: Access violation error"
- In reply to: Dan Cernat: "Re: default parameter value"
- Next in thread: Dan Cernat: "Re: default parameter value"
- Reply: Dan Cernat: "Re: default parameter value"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 03 Nov 2003 11:06:26 +0100
Dan Cernat wrote:
>
> "lilburne" <lilburne@godzilla.net> wrote in message
> news:bo32ll$17eop6$1@ID-203936.news.uni-berlin.de...
> > Rob Williscroft wrote:
> >
> > > earl wrote in news:3fa4db2d@news.broadpark.no:
> > >
>
> [snip]
>
> >
> > Quite right! I'm sure there is a valid reason for default
> > arguments, but I've never encountered one.
> >
>
> Avoid code duplication.
>
> void f(int a)
> {
> return a*2;
> }
>
> void f(int a, int b)
> {
> return a*b;
> }
>
> or, using default values:
> void f(int a, int b = 2)
> {
> return a*b;
> }
>
> of course, the example is trivial.
>
> /dan
... and could be solved without default arguments:
void f( int a, int b )
{
return a*b;
}
void f( int a )
{
return f( a, 2 );
}
This comes in handy, if the default arument is not constant, eg.
if the above is a member function of a class and the 'default argument'
is some class member.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: redgryphon_at_shaw.ca: "Condos in Canada @ 75 cents on the US Dollar!"
- Previous message: Frank Schmitt: "Re: Access violation error"
- In reply to: Dan Cernat: "Re: default parameter value"
- Next in thread: Dan Cernat: "Re: default parameter value"
- Reply: Dan Cernat: "Re: default parameter value"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|