www.digitalmars.com         C & C++   DMDScript  

D - Default Values

reply "Scott Egan" <scotte tpg.com.aux> writes:
I was looking at some example code and noticed that the author had used
extra versions of overloaded functions to achieve what amounted to default
values.

eg

foo(int a, int b)
{
    foo(a, b, 5)
}

foo(int a, int b, int c)
{
....
}

were if default values were supported:
foo(int a, int b, int c = 5)
{
....
}

would do the trick.  I appreciate that the compiler may be able to reduce
both to almost the same thing, but....

thoughts?
Apr 14 2004
parent Dave Sieber <dsieber spamnot.sbcglobal.net> writes:
"Scott Egan" <scotte tpg.com.aux> wrote:

 I was looking at some example code and noticed that the author had
 used extra versions of overloaded functions to achieve what amounted
 to default values.

 thoughts?

Personally, I like the C++ way of doing it (probably through familiarity over the years), as it seems simple, useful, and less verbose than writing a set of extra functions. But I think Walter may not like it for D. This has been discussed a lot recently. -- dave
Apr 14 2004