Sunday 29 March 2015

Passing Objects by Pointer

The members of objects passed by pointer are accessed by using the -> operator,
and they have similar effect as those passed by value. The above program requires
the following changes if parameters are to be passed by pointer.

? The prototype of the member function monetransfer() has to changed to

   Void monetransfer(ac *ac1, float amt);

? The definition of the member function moneytransfer() has to changed to

Void ac::moneytransfer(ac &ac1, float amt)
{
bal = bal – amt;
acc->bal = acc->bal + amt;
}

? The statement invoking the member function moneytransfer() has to changed to

Ac1.moneytransfer(&ac1, tmon);


No comments:

Post a Comment