I recommend using overloading for this particular task, as suggested by Lucian Grigore , but it would be common practice to reserve some value to say โthis is the default valueโ. for instance
int foo( int a, int b = -1) { if( b == -1){ b = a; } }
Using an object (not scalar values), this can be really well implemented (by creating a new class reserved for representing the default value), but with int you have to do it.
Note that you must be 100% sure that b cannot get the value -1 (or whatever your reserved value is).
source share