bigInt& bigInt::operator+=( const bigInt& b )
{
if( isPositive )
{
if( b.isPositive )
this->add( b );// lhs calling function
elsethis->subtract( b );// actual calcs in these functions
}
else// A is negative
{
if( b.isPositive )
this->subtract( b );
elsethis->add( b );
}
return *this;
}
There are many reasons to use this. Here are some:
* Ambiguity resolution. Member function has a parameter with the same name as member variable of the class. Within the function scope the parameter hides the member, but the member can be accessed with this. However, having such name clashes is IMHO bad style.
* Code clarity. bool Foo::equalX( const Foo & other ) const { return (this->x == other.x); } No syntactic ambiguity, but keep things clear for the reader.
* Return (reference to) object or its address. The pre-increment operator is an example.
* RTTI (runtime type information). See how and why Visitor design pattern accepts this.