2016-11-21 96 views
-1

編輯:我試圖創建一個客戶類,但有功能的問題。多繼承函數

這些是要遵循的指令:派生一個新類 - 客戶類(繼承自儲蓄 - 儲蓄繼承自銀行賬戶) 編寫客戶類。 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 = ""; 

    } 
}; 
+4

這裏有太多明顯的問題。你有更多的根本問題,而不僅僅是這個編譯錯誤。這個問題是無法挽救的... –

+1

您確定客戶是_Sales_Account和BankAccount嗎? –

回答

1

繼承的使用這裏糊塗。它應該看起來更像是這樣的:

class BankAccount { 
    // whatever 
}; 

class SavingsAccount : public BankAccount { 
    // whatever 
}; 

class Customer { 
    SavingsAccount savings; 
}; 

這是說一個SavingsAccount一個BankAccount,和一個Customer具有一個SavingsAccount

+0

我不知道原來的帖子是否會比'SavingAccount' +'CurrentAccount'更好。 –

+0

@JoeS - 發佈那個答案。這樣你就可以寫出實際的代碼,而不是有些不精確的描述。 –