Initializing default parameters from prior parameter

Adam D. Ruppe destructionator at gmail.com
Sat May 25 16:37:58 UTC 2019


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.


More information about the Digitalmars-d-learn mailing list