test a reference as a lvalue
This commit is contained in:
parent
9b2aef1701
commit
b987b2badd
3 changed files with 33 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,3 +15,4 @@ object-lifetime
|
|||
shared_ptr
|
||||
casts
|
||||
classes
|
||||
lvalues
|
||||
|
|
|
@ -15,3 +15,4 @@ add_executable(object-lifetime object-lifetime.cpp)
|
|||
add_executable(shared_ptr shared_ptr.cpp)
|
||||
add_executable(casts casts.cpp)
|
||||
add_executable(classes classes.cpp)
|
||||
add_executable(lvalues lvalues.cpp)
|
||||
|
|
31
lvalues.cpp
Normal file
31
lvalues.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <cassert>
|
||||
|
||||
int test = 12;
|
||||
|
||||
int fnord_(const int i) {
|
||||
test += i;
|
||||
return test;
|
||||
}
|
||||
|
||||
int& fnord(const int i) {
|
||||
test += i;
|
||||
return test;
|
||||
}
|
||||
|
||||
int main() {
|
||||
test = 13;
|
||||
|
||||
fnord_(5);
|
||||
assert(test == 18);
|
||||
|
||||
// LOLNOPE:
|
||||
// fnord_(5)++;
|
||||
|
||||
test = 13;
|
||||
|
||||
fnord(5);
|
||||
assert(test == 18);
|
||||
|
||||
fnord(5)++;
|
||||
assert(test == 24);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue