I was wondering which way to overload operators would be better. Pretend that Example is a class with one integer member x, and a constructor that takes one int and sets x to it.
Example 1:
Example 2:Code:const Example operator+(const Example &e) const { return Example(x + e.x); } Example &operator+=(const Example &e) { x += e.x; return *this; }
Is either way better than the other, or are they similar in terms of good practice, polymorphity (is that a word ?), and speed? Thanks !Code:const Example operator+(const Example &e) const { return Example(x + e.x); } Example &operator+=(const Example &e) { *this = *this + e; return *this; }