Signatures for class methods

Operators:

Here are some of the signatures for overloading operators:

const Class &operator=(const Class &Object); throw (EOutOfMemoryException);
friend Class operator+(const Class &Object1, const Class &Object2); throw (EOutOfMemoryException);
friend Class operator-(const Class &Object1, const Class &Object2); throw (EOutOfMemoryException);
const Class &operator+=(const Class &Object); throw (EOutOfMemoryException);
const Class &operator-=(const Class &Object); throw (EOutOfMemoryException);
friend int operator==(const Class &Object1, const Class &Object2);
friend int operator!=(const Class &Object1, const Class &Object2);
friend int operator<(const Class &Object1, const Class &Object2);
friend int operator>(const Class &Object1, const Class &Object2);
friend int operator<=(const Class &Object1, const Class &Object2);
friend int operator>=(const Class &Object1, const Class &Object2);

Most often then not, when you want to overload the assignment operator or the arithmetic operators, you would be performing memory allocations through the new() operator. If the allocation fails, the default behavior of new() is to throw an 'out-of-memory' exception. You should propagate such exceptions to the outside world.


Updated by Chirag Dalal.