May 25, 2019 Initializing default parameters from prior parameter | ||||
---|---|---|---|---|
| ||||
Wouldn't it make sense if this would be possible? It would shorten the function interface in cases, where no specialization of m is needed but still makes it possible to override.
myfunc(myObj o, myType m = o.getmyTypeValue()){...}
The compiler complains, that o is an undefined identifier.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
|
May 25, 2019 Re: Initializing default parameters from prior parameter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On Saturday, 25 May 2019 at 16:25:53 UTC, Robert M. Münch wrote:
> myfunc(myObj o, myType m = o.getmyTypeValue()){...}
I'd probably just write it
myType m = null) {
if(m is null) m = o.getmyTypeValue;
}
or
myfunc(myObj o) { /* use the default */ }
myfunc(myObj o, myType m) { /* use the provided m */ }
You might make the first one final if you only want the one overridden.
|
Copyright © 1999-2021 by the D Language Foundation