1

In C++, given the alternatives:

void fun(int arg1, int arg2opt = 0);

// vs.

void fun(int arg1, int arg2);
void fun(int arg1) {
  fun(arg1, 0);
}

Are there any differences for user code wanting to use this function, that is, given any code base, which code constructs would break (at compile time or runtime) when I were to change the first definition into the second? (Overload resolution? Name lookup? Assigning fun to a function pointer? Usage in templates (std::function)? ...)

Or will these be the same semantically? (here are some details that I know and that are not relevant for this question)

Community
  • 1
  • 1
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
  • Depends on where your "user code" is. Ex: Consider what happens when the "user" is a polymorphic derivation and these are virtual members. – WhozCraig Sep 13 '13 at 06:10
  • @WhozCraig: Yeah, virtual functions obviously are a difficult beast with default arguments anyway. – Martin Ba Sep 13 '13 at 09:40

1 Answers1

-1

i think this link is useful for start, but you named template, i have experienced in template , If your program is productive and don't have time to study to learn template, please stop, and learn templates in vacations.It doesn't have any quick ref and its erros a little differ with OOD/P , but if you have time, start it.

PersianGulf
  • 2,845
  • 6
  • 47
  • 67