Use consistent return types for assignment operators

Assignment operators should return a type that is consistent to the client. Usually this is a non-const reference, because that is what the built-in types and the standard C++ library classes return. Declare assignment operators like this:

      class TFoo {
          ...
          TFoo& operator=(argument);      // "argument" is usually: const TFoo &

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker