[Bug 191] New: Cannot refer to member variable in default value for method parameter

Deewiant deewiant.doesnotlike.spam at gmail.com
Sun Jun 11 11:58:01 PDT 2006


Jarrett Billingsley wrote:
> Is this even in the spec?  I had no idea you were supposed to be allowed to 
> use members as default parameters. 
> 

All I can find about default parameters in the spec is at the "Functions" page,
where they pop out of the blue in the phrase "A function parameter's default
value is not inherited", which is all that's said about them. The changelog for
DMD 0.92 also says "Added default arguments to function parameters. Semantics
are like C++." but that's it.

After some testing, it seems that that would actually explain it: C++ doesn't
allow it.

For what it's worth, I don't see any sense in this restriction - how is a
class's member different from any other variable in this situation? Especially
since the workaround is so simple, and isn't that all that default parameters
are meant to do - overload the method into a form which takes one less parameter
and passes the default value to the original? They don't have to implement it
that way, but that's how I see the semantics of it. And I'm not a compiler
writer, but it doesn't seem very difficult to implement either.



More information about the Digitalmars-d-bugs mailing list