Advertisement
Taraxacum

Equivalent Declaration

Dec 29th, 2020
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. // Two parameter declarations that differ only in their default arguments are equivalent.
  2.  
  3. #include <cstdio>
  4.  
  5. void func(double i);
  6.  
  7. void f(int i, int j);
  8. void f(int i, int j = 99); // OK: redeclaration of f(int, int)
  9. void f(int i = 88, int j); // OK: redeclaration of f(int, int)
  10. void f(); // OK: overloaded declaration of f
  11.  
  12. void prog()
  13. {
  14.     f(1, 2); // OK: call f(int, int)
  15.     f(1); // OK: call f(int, int)
  16.     // f(); // error: f(int, int) or f() ?
  17. }
  18.  
  19. int main(int argc, char const* argv[])
  20. {
  21.     prog();
  22.     return 0;
  23. }
  24.  
  25. void f(int i, int j)
  26. {
  27.     printf("i=%d, j=%d\n", i, j);
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement