Difference between revisions of "Cpp Coding Standards/FDESIGN/CanOp"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
 
Line 22: Line 22:
  
 
The operators '''&&''', '''||''' and ''',''' (comma) should never be overloaded.
 
The operators '''&&''', '''||''' and ''',''' (comma) should never be overloaded.
 +
[[Category:Coding Standards]]

Latest revision as of 17:10, 14 December 2009

Canonical Operators (CanOp)

<- Summary

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.

Personal tools