Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when a parameter is assigned a value in the function prototype?

Tags:

c++

I've just seen this syntax for a function prototype in C++:

explicit String(unsigned char value, unsigned char base=10);

I haven't seen this before, but am I right in assuming it sets base to 10 regardless of what you call it with?

like image 829
Ed King Avatar asked Jul 29 '13 14:07

Ed King


1 Answers

The default parameter, called base will take whatever value you send it, or the value 10, if you leave it off, e.g. by calling

String(0);

Given that you can call it with just one parameter, since the second can be defaulted, a constructor can be marked as explicit. This means it won't create a temporary from an unsigned char without you noticing, you have to explicitly call the constructor.

like image 58
doctorlove Avatar answered Sep 17 '22 07:09

doctorlove