TITLE: No way to express "use-default" for method calls [ Problem taken from "C++ Gotchas", tutorial notes by Tom Cargil, p. 52 ] Q: Given the code below, you, as a maintenance programmer, must change the default value of the second argument to f() from 2 to 5. How can you avoid having to chase down all the uses in the client code (as in main() below)? struct C { void f (int, int = 2, int = 3); }; int main () { C x; x.f (0, 2, 4); } The problem is that there is no way to express a value of "use default" when calling methods or functions. A: (From a Sim user) I just use the following. Yes, indeed it is legal Sim code (Thank You, Mark). f (0, , 4); A: Several C++ solutions to this problem are shown below. Each has strengths and weaknesses and vary in degree of complexity. o Use a constant or a variable for the default. + simplest solution - complex defaults may cause init order trouble - could pass constant in wrong position struct C { static const int kArgDefault2 = 2; static const int kArgDefault3 = 3; void f (int, int = kArgDefault2, int = kArgDefault3); }; int main () { C x; x.f (0, C::kArgDefault2, 4); } o Overload the function. + clients do not rely on the exact value of default - more complex than above solution - if f() is virtual, derived classes must wrap all methods struct defaultC { defaultC() {} }; struct C { void f (int, int = 2, int = 3); // no defaults void f (defaultC, int, int); // default arg1 void f (int, defaultC, int); // default arg2 }; int main () { C x; x.f (0, defaultC(), 4); } o Reify (make a class of) the arguments. + clients do not rely on the exact value of default + no pollution of class C with various versions of f() + no burden on derived classes due to virtual f() - more complex than above solution struct defaultC { defaultC() {} }; class CArgs { int fArg[3]; public: CArgs (int, int, int); // no defaults CArgs (defaultC, int, int); // default arg1 CArgs (int, defaultC, int); // default arg2 const int operator[] (int i) const { return fArg[i]; } }; struct C { void f (const CArgs&); }; int main () { C x; x.f (CArgs (0, defaultC(), 4)); } For this simple problem, some variation of solution #1 is probably the right balance of complexity and flexibility. Using reification (solution #3) can be valuable, particularly if the "gathered" arguments represent a viable abstraction.