C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
|
| < 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(Additive & Multiplicative) | +, -, *, /, % | 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&);iostream& operator>>(iostream& in, Foo&); |
| Increment & Decrement | ++, -- | Foo& operator++(); //postfixFoo& operator++(int); //prefix Foo& operator--(); //postfixFoo& operator--(int); //prefix |
| Function Call | () | Foo& operator()(int val1, int val2); |
| Subscript | [] | Foo& operator[](unsigned int); |
| Unary | *, &, +,-, !, ~ | Foo& operator+(); |
| Allocation & Deallocation | new, new[]delete, delete[] | Not covered in this chapter. |
|
| < Day Day Up > |
|