| < Day Day Up > |
|
Table 14.1 lists the overloadable operators. The right hand column gives an example prototype for one of the operators in the group for a user-defined type named Foo.
Operator Type | Operators | Example Prototype For Class Foo |
---|---|---|
Arithmetic | +, -, *, /, % | Foo& operator+(Foo& lhs, Foo& rhs); |
Assignment | = | Foo& operator=(Foo& rhs); |
Compound Assignment | *=, /=, %=, +=, -=, >>=, <<=, &=, ^=, |= | Foo& operator+=(Foo& rhs); |
Relational | <, >, <=. >=, | bool operator<(Foo& rhs); |
Logical | !, &&, || | bool operator!(Foo& rhs); |
Equality | ==, != | bool operator==(Foo& rhs); |
Shift | <<, >> | Foo& operator<<(int shift_by); |
Bitwise | &, |, ^ | Foo& operator&(int mask_value); |
Comma | , | Foo& operator,(Foo& rhs); |
Pointer-to-Member | ->, ->* | Foo* operator->(); |
IOStream Insertion & Extraction | <<, >> | iostream& operator<<(iostream& out, Foo&); |
Increment & Decrement | ++, -- | Foo& operator++(); //postfix Foo& operator--(); //postfix |
Function Call | () | Foo& operator()(int val1, int val2); |
Subscript | [] | Foo& operator[](unsigned int); |
Unary | *, &, +,-, !, ~ | Foo& operator+(); |
Allocation & Deallocation | new, new[] | Not covered in this chapter. |
| < Day Day Up > |
|