Nonstatic member functions have an implied argument, this, that points to the object through which the function is invoked. The type of this is type * const. These functions are considered to have class scope and can use class data and other member functions in the same class scope directly. In the preceding example, the expression balance += HowMuch
adds the value of HowMuch
to the class member balance
. Consider the following statements:
Account Checking;
Checking.Deposit( 57.00 );
The preceding code declares an object of type Account
and then invokes the member function Deposit
to add $57.00 to it. In the function Account::Deposit
, balance is taken to mean Checking.balance
(the balance member for this object).
Nonstatic member functions are intended to operate on objects of their class type. Calling such a function on objects of different types (using explicit type conversions) causes undefined behavior.