diff --git a/.gitignore b/.gitignore index 3530b24..eb1a3e2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ object-lifetime shared_ptr casts classes +lvalues diff --git a/CMakeLists.txt b/CMakeLists.txt index 2256cd5..d03d752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/lvalues.cpp b/lvalues.cpp new file mode 100644 index 0000000..998dbf3 --- /dev/null +++ b/lvalues.cpp @@ -0,0 +1,31 @@ +#include + +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); +}