digitalmars.D.learn - Initializing default parameters from prior parameter
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (9/9) May 25 2019 Wouldn't it make sense if this would be possible? It would shorten the
- Adam D. Ruppe (10/11) May 25 2019 I'd probably just write it
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
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.
May 25 2019