2 bool optional params

Jonathan M Davis jmdavisProg at gmx.com
Wed Nov 10 00:30:55 PST 2010


On Tuesday 09 November 2010 23:55:26 spir wrote:
> Hello,
> 
> Is there a way for a func to hold 2 optional params of the same type?
> 	void f(int p, bool b1=false, bool b2=false) {
> 	    writefln("p=%s b1=%s b2=%s", p,b1,b2);
> 	 }
> Or is there a workaroud?

Try compiling it. It works just fine.

You should be able to have multiple optional parameters, and their types 
shouldn't matter. Where you get into trouble is if that function has overloads 
which conflict. Since, in effect, by declaring

void f(int p, bool b1 = false, bool b2 = false)

you've declared

void f(int p, bool b1, bool b2)
void f(int p, bool b1)
void f(int p)

So, trying to declare any of those three separately won't work because your first 
definition covers them all.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list