I could use some help understanding the following in C++, particularly the difference between an operator and a function:
operator+()
a function or an operator?sizeof()
in C++)5 Answers. Show activity on this post. Loosely, an operator (acting on a function space) takes functions to functions (e.g., f(x) to −if′(x)). On the other hand, a functional takes functions to numbers (think about a certain integral, or the derivative evaluated at a certain point).
Solution. The basic difference between operator function as a friend function and as member function is that a friend function will have only one argument for unary operators and only one for binary operators.
An operator is a symbol like +
, -
, +=
and so forth (see 13.5). They don't carry a meaning. During semantic analysis, the meaning of an operator is determined.
A function is a constructor, destructor, conversion function (that looks like operator type()
) or operator function (function template specialization and instantiation can yield these in turn).
An operator function is something that implements an operator (see 13.5). An example is operator+
. These are functions in all respects, and the only difference to "usual" functions is that they may be called implicitly and they have a funny name.
Some operators have a built-in meaning, that can be changed by the programmer. One refers to the built-in meaning of an operator simply by saying built-in operator (see 5/3). However, if such an operator is applied on operands for which a built-in meaning is defined, changing that meaning is only allowed for a few cases (these are assignment, address-of and the comma operator, see 13.5/6).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With