# Cpp Coding Standards/FDESIGN/CanOp

From Apache OpenOffice Wiki

## Contents

### Canonical Operators (CanOp)

#### Details

If you overload an operator, always give it its canonical signature and semantic, that is the same one, as if it would be manipulating integers.

##### Arithmetic Operators

Assignment operators return a non const reference:

T & T::operator=(const T &);

If you provide an arithmetical operator, provide the assignment form as well. That is together with

T T::operator+(const T &) const;

provide

T & operator+=(const T &);

##### Boolean Operators

Boolean operators always return **bool**, not **int**:

bool operator<(const T&, const T&);

#### Exceptions

The shift operators **<<** and **>>** are usually overloaded in a different way, not resembling their use on integers.

The operators **&&**, **||** and **,** (comma) should never be overloaded.