Sreekar
Sreekar

Reputation: 1025

calling a function in C++ with default arguments

I have a function Func(string str,int*i=NULL,int*j=NULL,bool ok=false); I called it as Func(some_string,false);

And program is crashing..Because the order I'm calling with --is wrong??

Upvotes: 2

Views: 190

Answers (2)

Darzen
Darzen

Reputation: 1165

Yes. The second parameter is expecting a int value and you are passing a bool value. The 3rd and 4th parameters will take NULL and false respectively.

Upvotes: 0

NPE
NPE

Reputation: 500923

If you wish to specify a value for ok, you also have to specify values for all arguments that precede it.

Upvotes: 2

Related Questions