Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int f(int){ /* can write to parameter */}
- int f(const int){ /* cannot write to parameter */}
- f(3);
- int x = 1 + 2;
- f(x);
- void f(const int&) { ... }
- void f(int&) { ... }
- const
- F
- T f(F& x_ref)
- {
- F x = x_ref; // or const F is you won't modify it
- ...use x for safety...
- }
- void foo(const int);
- void foo(int);
- // declarations
- void foo(int);
- void bar(int);
- // definitions
- void foo(int n)
- {
- n++;
- std::cout << n << std::endl;
- }
- void bar(const int n)
- {
- n++; // ERROR!
- std::cout << n << std::endl;
- }
- void foo()
- {
- int = 42;
- n++;
- std::cout << n << std::endl;
- }
- void bar()
- {
- const int n = 42;
- n++; // ERROR!
- std::cout << n << std::endl;
- }
- void f(int);
- void f(const int);
- void f(int);
- void f(const int);
- f(42); // calls void f(int);
- int foo(const int);
- int foo(int);
- int foo(const int i) { return i*i; }
- int foo(int i) { return i*2; }
Add Comment
Please, Sign In to add comment