Sunday, November 7, 2010


a += b is more efficient than a = a + b.

The operator+() typically needs to create a temporary (e.g. MyClass temp(a);temp+=a;return a;); whereas operator+=() can just update its object (e.g. m_a += b.m_a;)

Reference: Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions by Herb Sutter. Addison-Wesley, 1999, p. 71.

No comments:

Post a Comment