Cpp Coding Standards/FDESIGN/CanOp

From Apache OpenOffice Wiki
Jump to: navigation, search

Canonical Operators (CanOp)

<- Summary


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;


T & operator+=(const T &);
Boolean Operators

Boolean operators always return bool, not int:

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


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.

Personal tools