Re: default parameter value

From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 11/03/03


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


Relevant Pages

  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)
  • problem in java swings
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • ToolTips in a View and TTN_NEEDTEXT
    ... extern int g_minWorkPeriod; ... void CDayView::CreateAllFonts ... void CDayView::DrawDayLog(CDC* pDC) ... BOOL CDayView::TimeToY ...
    (microsoft.public.vc.mfc)