Other operators
| Operator name | Syntax | Overloadable | Prototype examples (for class T) | |
|---|---|---|---|---|
| Inside class definition | Outside class definition | |||
| function call | a(a1, a2) | Yes | R T::operator()(Arg1 &a1, Arg2 &a2, ... ...); | N/A |
| comma | a, b | Yes | T2& T::operator,(T2 &b); | T2& operator,(const T &a, T2 &b); |
| conversion | (type) a | Yes | operator type() | N/A |
| ternary conditional | a ? b : c | No | N/A | N/A |
Contents |
[edit] Explanation
function call operator provides function semantics for any object.
conversion operator converts given type to another type. The name of the operator must be the same as the type intended to be returned.
ternary conditional operator checks the boolean value of the first expression and replaces entire operator clause with the second or the third expression depending on the resulting value.
[edit] Built-in function call operator
A function call expression consists of an expression that names the function, E, followed by a possibly empty list of expressions A1, A2, A3, in parentheses: E(A1, A2, A3).
The expression that names the function can be
The function (or member) name specified by E can be overloaded, overload resolution rules used to decide which overload is to be called.
If E specifies a member function, it may be virtual, in which case the final overrider of that function will be called, using dynamic dispatch at runtime.
To call the function, all expressions A1, A2, A3, etc, provided as arguments are evaluated in arbitrary order, and each function parameter is initialized with its corresponding argument after implicit conversion if neccessary. If the call is made to a member function, then the this pointer to current object is converted as if by explicit cast to the this pointer expected by the function. The initialization and destruction of each parameter occurs in the context of the caller, which means, for example, that if constructor of a parameter throws an exception, the exception handlers defined within the function, even as a function-try block, are not considered.
| This section is incomplete Reason: va_args rules |
The return type of a function call expression is the return type of the chosen function, decided using static binding (ignoring the virtual) keyword), even if the overriding function that's actually called returns a different type. This allows the overriding functions to return pointers or references to classes that are derived from the return type returned by the base function, i.e. C++ supports covariant return types). If E specifies a destructor, the return type is void.
The value category of a function call expression is lvalue if the function returns an lvalue reference or an rvalue reference to function, is an xvalue if the function returns an rvalue reference to object, and is a prvalue otherwise. If the function call expression is a prvalue of object type, it must have complete type except when used as an operand to decltype.
Function call expression is similar in syntax to value initialization T(), to function-style cast expression T(A1), and to direct initialization of a temporary T(A1, A2, A3, ...).
| This section is incomplete |
[edit] Built-in comma operator
| This section is incomplete |
[edit] Built-in conversion operator
The built-in conversion operator performs cpp/language/explicit_cast.
| This section is incomplete |
[edit] Conditional operator
| This section is incomplete |
[edit] Standard library
| This section is incomplete |
[edit] See also
| Common operators | ||||||
|---|---|---|---|---|---|---|
| assignment | increment decrement |
arithmetic | logical | comparison | member access |
other |
|
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
| Special operators | ||||||
|
static_cast converts one type to another compatible type | ||||||