Key Points
- There are lvalues and rvalues:
- In
x = y + z
,x
is an lvalue andy + z
is an rvalue. - lvalues have an obvious memory location and significant lifetime; they often have a name.
- rvalues are temporary values that exist for the duration of one line of code; they often don't have names.
- In
- Every function call that returns a value is actually initializing a new object in memory
- The compiler allocates temporary objects (rvalues) as needed (e.g., to hold intermediate results in nested expressions).
- Functions can return references.
- We can overload functions (i.e., define multiple functions with the same name that operate on different sets of arguments).
- C++ uses the types of the arguments of the function to figure out which function we mean to call. If selecting the best function for a particular set of arguments is ambiguous, it's an compile-time error.
- We can implement our own versions of C++'s existing operators for our own types, so we can make our types feel “built in”.
(When logged in, completion status appears here.)