Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
operator= is an operator, that is called the
assign operator and assignment operator.
In class design, have assignment
operators return a reference to *this [1,3].
In class design, also handle assignment to self [2,4].
To handle assignment to self there are two techniques: 'identity test' or 'copy
and swap'.
Handle assignment to self: Identity test
Handle assignment to self: Copy and swap
- Scott Meyers. Effective C++ (3rd edition).ISBN: 0-321-33487-6. Item 10: Have assignment operators return a reference to *this.
- Scott Meyers. Effective C++ (3rd edition).ISBN: 0-321-33487-6. Item 11: Handle assignment to self in operator=.
- Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and Demonstration Program. Document Number 2RDU00001 Rev C. December 2005. AV Rule 82: 'An assignment operator shall return a reference to *this.'
- Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and Demonstration Program. Document Number 2RDU00001 Rev C. December 2005. AV Rule 81: 'The assignment operator shall handle self-assignment correctly'
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
