Download User's Guide

Transcript
Item ecpp_17
Items Enforced
Item ecpp_17
Check for assignment to self in
operator=
CodeWizard checks your code for aliasing in assignment operators.
Errors are marked as violations of Item ecpp_17.
Reason for rule: Not checking for assignment to self in operator= can
free resources that might be needed during the process of allocating new
resources. Checking for assignment to self may also save you a lot of
work that you would otherwise have to do to implement assignments.
Example
/*
* Item 17 - Check for assignment to self in operator=
*/
class A{
public:
A() {}
A& operator=(A& a)
// ECPP item 17 violation
{
_i = a._i;
return *this;
}
private:
int _i;
};
int main()
{
85