According to the C++ identifier naming rules:
A valid identifier is a sequence of one or more letters, digits, or underscore characters (_) and must start either with a letter or underscore. Spaces, punctuation marks, and symbols cannot be part of an identifier.
But the name of a function for operator overloading can contain characters other than a letter, digit or underscore, like for example:
user_data_type operator+(const user_data_type & t) const;
Is this an exception to the the identifier naming rules or does function names used for operator overloading not considered as an identifier?
Which is the correct statement about operator overloading? Explanation: Both arithmetic and non-arithmetic operators can be overloaded. The precedence and associativity of operators remains the same after and before operator overloading. 10.
8. Which of the following statements is NOT valid about operator overloading? Explanation: The overloaded operator must not have at least one operand of its class type. Explanation: Operator overloading is the way adding operation to the existing operators.
operator+
is not a normal identifier, it is an operator-function-id as defined in 13.5/1 in N4140. By definition, it consists of the word operator
followed by an operator, the +
in your example. By this rule, you can also write
operator +
or even
user_data_type
operator
+
(const user_data_type & t) const;
as again, operator+
is not a normal identifier.
The rule you cite does not apply here.
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