Chapter Summary
An overloaded operator must either be a member of a class or have at least one operand of class type. Overloaded operators have the same number of operands, associativity, and precedence as the corresponding operator when applied to the built-in types. When an operator is defined as a member, its implicit this
pointer is bound to the first operand. The assignment, subscript, function-call, and arrow operators must be class members.
Objects of classes that overload the function-call operator, operator()
, are known as “function objects.” Such objects are often used in combination with the standard algorithms. Lambda expressions are succinct ways to define simple function-object classes.
A class can define conversions to or from its type that are used automatically. Nonexplicit
constructors that can be called with a single argument define conversions from the parameter type to the class type; nonexplicit
conversion operators define conversions from the class type to other types.