Skip to Main Content
C++ In a Nutshell
book

C++ In a Nutshell

by Ray Lischner
May 2003
Intermediate to advanced content levelIntermediate to advanced
808 pages
32h 24m
English
O'Reilly Media, Inc.
Content preview from C++ In a Nutshell

Name

operator keyword — Function call syntax for operators

Synopsis

               operator-function-id ::= operator op-symbol | 
    operator op-symbol < [template-arg-list] >
conversion-function-id ::= operator conversion-type-id
               conversion-type-id ::= type-specifier-seq [conversion-declarator]
conversion-declarator ::= ptr-operator [conversion-declarator]
ptr-operator ::= * [cv-qualifier-seq] | & | [::] nested-name :: * [cv-qualifier-seq]

The operator keyword converts an operator symbol into function notation. You can use the operator keyword when invoking an operator or when overloading an operator.

Example

int x =operator+(10, 32);
complex<double> c, d;
c.operator+=(d);
operator+=(c, d); // Same as above
bigint operator*(const bigint& a, const bigint* b);

Table 12-1 lists the operator symbols (op-symbol) that can be overloaded. Alternative tokens (shown in parentheses) are interchangeable with their symbolic equivalents.

Table 12-1. Operator symbols that can be overloaded

delete

/

=

%=

<<=

++

delete [ ]

%

<

^= (xor_eq)

==

--

new

^ (xor)

>

&= (and_eq)

!= (not_eq)

,

new [ ]

& (bitand)

+=

|= (or_eq)

<=

->*

+

| (bitor)

-=

<<

>=

->

-

~ (compl)

*=

>>

&& (and)

( )

*

! (not)

/=

>>=

|| (or)

[ ]

See Also

expression, identifier, template, type, Chapter 5

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ High Performance

C++ High Performance

Viktor Sehr, Björn Andrist
Optimized C++

Optimized C++

Kurt Guntheroth
Mastering C++ Programming

Mastering C++ Programming

Jeganathan Swaminathan

Publisher Resources

ISBN: 059600298XSupplemental ContentErrata Page