我正在尝试使用派生类CheckingAccount创建BankAccount类。我遇到的问题如下:
BankAccount.h
class BankAccount {
private:
/* ATTRIBUTES */
int accountNumber;
double balance;
public:
/* METHODS */
BankAccount();
void setAccountNumber( int );
void deposit( double );
int getAccountNumber();
int getBalance();
double withdraw( double );
};
CheckingAccount.h
#include "BankAccount.h"
class CheckingAccount: public BankAccount {
private:
/* ATTRIBUTES */
int withdrawalAmount;
double balance;
/* METHODS */
public:
/* METHODS */
CheckingAccount();
};
CheckingAccount.cpp
#include "CheckingAccount.h"
CheckingAccount::CheckingAccount() {
//Initialize
}
double CheckingAccount::withdraw( double a ) {
//This doesn't work.
}
答案 0 :(得分:2)
只需在BankAccount类中进行虚拟撤销,并在CheckingAccount中声明它。
virtual double withdraw( double );