void foo(Type1 a, Type2 b = value2)
May I know what are the restrictions of Type2 to be a parameter that accepts default value? I reckon value2 of type2 should be decidable at compile time. For example, an integer. Is this correct?
void foo(Type1 a, Type2 b = value2)
May I know what are the restrictions of Type2 to be a parameter that accepts default value? I reckon value2 of type2 should be decidable at compile time. For example, an integer. Is this correct?
You have quite a lot of flexibility.
value2needs to be an expression which is valid at the point of declaration of the function (by "valid" I mean that the names it uses are in scope, etc), and its type must be implicitly convertible toType2, same as for any initializer.value2is evaluated each time the function is called. So for example:With the right initializer,
Type2can even be a reference type: