Overloading the assignment operator
Reference declaration
Reference declaration
C++ allows reference declarations so you can create aliases for variables.
These declarations are typically of the form:
type& identifier = variable
Reference declarations declare the identifier to be an alternative name, or alias, for a variable specified in an initialization of the reference. In effect, reference declarations produce lvalues:
Using reference declarations can avoid this overhead. Multiple assignment expressions ordinarily require the creation of temporaries to perform them. By using reference return types, this can be managed efficiently. For ADTs, we must define such expressions unless satisfactory defaults are available.
These declarations are typically of the form:
type& identifier = variable
Reference declarations declare the identifier to be an alternative name, or alias, for a variable specified in an initialization of the reference. In effect, reference declarations produce lvalues:
- On the right side of an assignment expression, an lvalue is automatically dereferenced.
- On the left side, it specifies where an appropriate value is to be stored.
Using reference declarations can avoid this overhead. Multiple assignment expressions ordinarily require the creation of temporaries to perform them. By using reference return types, this can be managed efficiently. For ADTs, we must define such expressions unless satisfactory defaults are available.