operator-function-id: operator operator
operator: one of new delete new[] delete[] ( ) [ ] -> ->* ~ ! + - * / % ^ & | = += -= *= /= %= ^= &= |= == != < > <= >= <=> && || << >> <<= >>= ++ – ,
complex z = a.operator+(b); // complex z = a+b;
void* p = operator new(sizeof(int)*n);
— end examplestruct B { virtual int operator= (int); virtual B& operator= (const B&); }; struct D : B { virtual int operator= (int); virtual D& operator= (const B&); }; D dobj1; D dobj2; B* bptr = &dobj1; void f() { bptr->operator=(99); // calls D::operator=(int) *bptr = 99; // ditto bptr->operator=(dobj2); // calls D::operator=(const B&) *bptr = dobj2; // ditto dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&) }— end example
postfix-expression ( expression-list )where the postfix-expression evaluates to a class object and the possibly empty expression-list matches the parameter list of an operator() member function of the class.
postfix-expression [ expr-or-braced-init-list ]
struct X { Z operator[](std::initializer_list<int>); }; X x; x[{1,2,3}] = 7; // OK: meaning x.operator[]({1,2,3}) int a[10]; a[{1,2,3}] = 7; // error: built-in subscript operator— end example
postfix-expression -> template id-expression postfix-expression -> pseudo-destructor-name
struct X { X& operator++(); // prefix ++a X operator++(int); // postfix a++ }; struct Y { }; Y& operator++(Y&); // prefix ++b Y operator++(Y&, int); // postfix b++ void f(X a, Y b) { ++a; // a.operator++(); a++; // a.operator++(0); ++b; // operator++(b); b++; // operator++(b, 0); a.operator++(); // explicit call: like ++a; a.operator++(0); // explicit call: like a++; operator++(b); // explicit call: like ++b; operator++(b, 0); // explicit call: like b++; }— end example
literal-operator-id: operator string-literal identifier operator user-defined-string-literal
const char* unsigned long long int long double char wchar_t char16_t char32_t const char*, std::size_t const wchar_t*, std::size_t const char16_t*, std::size_t const char32_t*, std::size_t
void operator "" _km(long double); // OK string operator "" _i18n(const char*, std::size_t); // OK template <char...> double operator "" _\u03C0(); // OK: UCN for lowercase pi float operator ""_e(const char*); // OK float operator ""E(const char*); // error: reserved literal suffix ([usrlit.suffix], [lex.ext]) double operator""_Bq(long double); // OK: does not use the reserved identifier _Bq ([lex.name]) double operator"" _Bq(long double); // uses the reserved identifier _Bq ([lex.name]) float operator " " B(const char*); // error: non-empty string-literal string operator "" 5X(const char*, std::size_t); // error: invalid literal suffix identifier double operator "" _miles(double); // error: invalid parameter-declaration-clause template <char...> int operator "" _j(const char*); // error: invalid parameter-declaration-clause extern "C" void operator "" _m(long double); // error: C language linkage— end example