Function calls
Once a function has been declared and defined, it can be called from
anywhere within the program: from within the main function,
from another function, and even from itself. Calling the function
involves specifying the function name, followed by the function call
operator and any data values the function expects to receive. These
values are the arguments for the parameters defined for the
function, and the process just described is called passing arguments to
the function.
A
function may not be called if it has not already been declared.
- Pass by value, which copies the value of an argument to the corresponding parameter in the called function
- Pass by reference, which passes the address of an argument to the corresponding parameter in the called function
Beginning of C++ only.
If a class has a destructor or a copy constructor that does more than a bitwise copy, passing a class object by value results in the construction of a temporary object that is actually passed by reference.
- The class needs a copy constructor.
- The class does not have a user-defined copy constructor.
- A copy constructor cannot be generated for that class.
End of C++ only.
A function call expression is always an rvalue.
A function call belongs to one of the following value categories depending on the result
type of the function:
- An lvalue if the result type is an lvalue reference type or
an rvalue reference to a function type
An xvalue if the result type is an rvalue
reference to an object type- A
(prvalue) rvalue in other cases