c++ - How to give an argument a default value determined by a function of the other arguments -
in c++ function multiple arguments, 1 of arguments have default value function of other arguments. example,
int f1( int m ); int f2( int n1, int n2 = f1( n1 ) ) { // stuff n1 , n2 }
this won't compile, makes clear behavior want function f2. caller should able manually pass value n2, default value of n2 should determined calling f1 on n1. suggestions how best implement (or @ least approximate) behavior?
overload function instead:
int f1( int m ); int f2( int n1, int n2 ) { // stuff n1 , n2 } int f2( int n1 ) { return f2( n1, f1( n1 ) ); }
Comments
Post a Comment