Brand new operator_person is sometimes an effective semicolon, a beneficial block body (§fourteen

Brand new operator_person is sometimes an effective semicolon, a beneficial block body (§fourteen

.step 1 General

An operator is actually an associate one to defines this is of an enthusiastic phrase agent which is often placed on cases of the class. Workers are proclaimed playing with operator_declarations:

6.1) datingranking.net/tr/beetalk-inceleme or an expression human body (§fourteen.six.1). A great cut off system consists of a good cut off, and that specifies the fresh statements to do if agent try invoked. The newest take off shall conform to the guidelines having value-coming back procedures demonstrated inside the §fourteen.six.11. An expression muscles includes => followed closely by a phrase and you may a great semicolon, and denotes just one phrase to do in the event the agent try invoked.

Getting extern providers, brand new agent_muscles comprise simply of a good semicolon. For everyone most other providers, the latest user_person is possibly a good cut off body or a phrase body.

  • An agent statement should tend to be one another a public and you can a static modifier.
  • New parameter(s) out-of an operator will do not have modifiers.
  • The newest trademark from an agent (§.dos, §.step three, §.4) shall differ from the fresh signatures of the many almost every other operators age classification.
  • All types referenced inside an operator statement will be about as the accessible because agent by itself (§7.5.5).
  • It’s an error for similar modifier to appear numerous times during the an operator statement.

Like many members, workers declared within the a base classification was passed down from the derived groups. Since driver declarations always require the class otherwise struct where the latest agent try stated to participate in brand new trademark of your driver, this is simply not simple for an operator stated in an effective derived class to full cover up a driver stated in the a base group. Therefore, the modifier is never requisite, hence never ever let, inside the an user declaration.

.2 Unary providers

The second rules connect with unary operator declarations, where T indicates the newest such kind of the class or struct that contains the newest user report:

, ++ , — , true , or false ) and the version of the newest unmarried official factor. Brand new get back type of isn’t part of a unary operator’s signature, nor ‘s the title of your own official factor.

The genuine and you may incorrect unary workers require partners-smart declaration. A compile-time error takes place when the a course announces one operators instead of in addition to declaring others. The true and you can untrue operators are revealed after that when you look at the §.

Mention the way the operator strategy efficiency the value created by including step 1 towards operand, given that postfix increment and decrement operators (§11.seven.14), and the prefix increment and decrement workers (§11.8.6). Instead of when you look at the C++, this procedure cannot modify the worth of the operand directly because this carry out violate the high quality semantics of your postfix increment agent (§11.eight.14). stop example

.step three Binary operators

The second guidelines apply to digital driver declarations, in which T indicates the latest such as for example types of the class or struct which has the fresh new operator report:

  • A digital low-shift agent should simply take one or two variables, one or more of which will features variety of T or T? , and will come back any sort.
  • A binary << or >> operator (§) shall take two parameters, the first of which shall have type T or T? and the second of which shall have type int or int? , and can return any type. The signature of a binary operator consists of the operator token ( + , – , * , / , % , , | , ^ , << , >> , == , != , > , < , >= , or <= ) and the types of the two formal parameters. The return type and the names of the formal parameters are not part of a binary operator's signature.

Particular binary operators require couple-wise report. For each statement of either operator out-of moobs, around are a matching declaration of one’s most other user from the two. A couple driver declarations fits in the event that name conversion rates exists ranging from their come back designs in addition to their corresponding factor models. Next operators want pair-wise declaration: