operator+() should not be a member function.
This is so that the operator performs more like the built-in operators. For example, if you allow some implicit conversions, then if you make operator+() a member function, the implicit converstions will only work on the RHS (right hand side).
For example: 'MyObject + 1' may compile, while '1 + MyObject' may not.
Reference: Exceptional C++ by Herb Sutter. Addison-Wesley, 1999, p. 72.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment