Default function parameters of other function parameters

Your name email at example.com
Tue Oct 30 21:54:11 UTC 2018


I think it would be nice if default function parameters could be 
defined as other parameters to the function, like this:
========CODE========
class Rectangle
{
     int width;
     int height;

     this(int initialWidth, int initialHeight = initialWidth) {
         width = initialWidth;
         height = initialHeight;
     }
}

void main()
{
     import std.stdio;
     auto myRectangle = new Rectangle(5, 17);
     auto mySquare = new Rectangle(5);//pass only one parameter to 
make a square
}
========END OF CODE===

Side note: Am I missing something, or is there no code snippets 
on these forums? `backticks` don't do anything. Being a forum 
about a programming language, there should really be a way to 
embed snippets of code 😆!


More information about the Digitalmars-d mailing list