11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

286Part IV: InheritanceDescribing the abstract class conceptAn abstract class is a class with one or more pure virtual functions. Oh, great!That helps a lot.Okay, a pure virtual function is a virtual member function that is marked ashaving no implementation. Most likely it has no implementation becauseno implementation is possible with the information provided in the class,including any base classes.It doesn’t make sense to ask exactly how to implement the withdrawal()function in the class Account. However, the concept of a withdrawal froman account does make sense. The C++ programmer can write a functionwithdrawal() that is impossible to implement. Such a function is calleda pure virtual function. (Don’t ask me how they came up with that name.)The syntax for declaring a function pure virtual is demonstrated in the followingclass Account:// Account - this class is an abstract classclass Account{protected:Account(Account& c); // avoid making any copiespublic:Account(unsigned accNo, float initialBalance = 0.0F);// access functionsunsigned int accountNo( );float acntBalance( );static int noAccounts( );// transaction functionsvoid deposit(float amount);// the following is a pure virtual functionvirtual void withdrawal(float amount) = 0;protected:// keep accounts in a linked list so there’s no limit// to the number of accountsstatic int count; // number of accountsunsigned accountNumber;float balance;};The = 0 after the declaration of withdrawal() indicates that the programmerdoes not intend to define this function. The declaration is a placeholder for thesubclasses. The subclasses of Account are expected to override this function

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!