Guest User

Untitled

a guest
Jan 11th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. int f(int){ /* can write to parameter */}
  2. int f(const int){ /* cannot write to parameter */}
  3.  
  4. f(3);
  5. int x = 1 + 2;
  6. f(x);
  7.  
  8. void f(const int&) { ... }
  9. void f(int&) { ... }
  10.  
  11. const
  12.  
  13. F
  14.  
  15. T f(F& x_ref)
  16. {
  17. F x = x_ref; // or const F is you won't modify it
  18. ...use x for safety...
  19. }
  20.  
  21. void foo(const int);
  22. void foo(int);
  23.  
  24. // declarations
  25. void foo(int);
  26. void bar(int);
  27.  
  28. // definitions
  29. void foo(int n)
  30. {
  31. n++;
  32. std::cout << n << std::endl;
  33. }
  34.  
  35. void bar(const int n)
  36. {
  37. n++; // ERROR!
  38. std::cout << n << std::endl;
  39. }
  40.  
  41. void foo()
  42. {
  43. int = 42;
  44. n++;
  45. std::cout << n << std::endl;
  46. }
  47.  
  48. void bar()
  49. {
  50. const int n = 42;
  51. n++; // ERROR!
  52. std::cout << n << std::endl;
  53. }
  54.  
  55. void f(int);
  56. void f(const int);
  57.  
  58. void f(int);
  59. void f(const int);
  60.  
  61. f(42); // calls void f(int);
  62.  
  63. int foo(const int);
  64. int foo(int);
  65.  
  66. int foo(const int i) { return i*i; }
  67. int foo(int i) { return i*2; }
Add Comment
Please, Sign In to add comment