多继承函数
问题描述:
编辑:我试图创建一个客户类,但有功能的问题。多继承函数
这些是要遵循的指令:派生一个新类 - 客户类(继承自储蓄 - 储蓄继承自银行账户) 编写客户类。 Customer类具有以下新的属性 客户名称
关于如何解决我的职能的任何方向将有助于
#include "BankAccount.h"
#include "SavingsAccount.h"
#include <iostream>
class Customer : public SavingsAccount, public BankAccount {
protected:
string CustomerName;
public:
string getCustomerName();
void setCustomerName(string);
void WithdrawSavings(){ Customer c; c.BankAccount::balance(); }
void DepositSavings(double);
Customer(){
CustomerName = "";
}
};
答
继承的使用这里糊涂。它应该看起来更像是这样的:
class BankAccount {
// whatever
};
class SavingsAccount : public BankAccount {
// whatever
};
class Customer {
SavingsAccount savings;
};
这是说一个SavingsAccount
是一个BankAccount
,和一个Customer
具有一个SavingsAccount
。
+0
我不知道原来的帖子是否会比'SavingAccount' +'CurrentAccount'更好。 –
+0
@JoeS - 发布那个答案。这样你就可以写出实际的代码,而不是有些不精确的描述。 –
这里有太多明显的问题。你有更多的根本问题,而不仅仅是这个编译错误。这个问题是无法挽救的... –
您确定客户是_Sales_Account和BankAccount吗? –