#include <iostream> #include <vector> class Account { public: virtual void PrintBalance() { std::cout<<"Base"<<std::endl; } }; class SavingAccount : public Account { public: void PrintBalance() { std::cout<<"SavingAccount"<<std::endl; } }; class CurrentAccount : public Account { public: void PrintBalance() { std::cout<<"CurrentAccount"<<std::endl; } }; int main() { Account *pAccount=NULL; SavingAccount objsavingAccount; CurrentAccount objcurrentAccount; pAccount = &objsavingAccount; pAccount ->PrintBalance(); pAccount = &objcurrentAccount; pAccount ->PrintBalance(); return 0; }
OutPut: SavingAccount CurrentAccount
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)