Thursday, January 20, 2011

error: invalid initialization of non-const reference of type <> from a temporary of type

Solution: Don’t ever pass temporary object by reference.
Reason: C++ doesn't allow to bind the temporary object with non-const reference.

This is not about performance, but about the fact that you do or may alter the original, which you are not allowed to if that original is a temporary. Passing by value instead of by reference, we wouldn't have the problem.

No comments:

Post a Comment