I have made a base class and a derived class and I am having a couple compile errors.
SavingsAccount.hpp(9) : error C2512: 'Account' : no appropiate default constructor available
What i want to do is be able to give the savings account an inital balance and it changes the currentBalance variable in the account class.
Base class
#include <iostream>
using namespace std;
class Account {
friend class SavingsAccount;
//friend class CheckingAccount;
double deposit;
//double withdrawal;
public:
Account(double newBalance) {//, double deposit, double withdrawal) {
currentBalance = newBalance;
//newBalance >= 0 ? currentBalance += newBalance : cout << "Initial balance invalid";
};
~Account() { };
int getBalance() { return currentBalance; }
void credit() { currentBalance += deposit; }
//void debit() { currentBalance >= withdrawal ? currentBalance -= withdrawal : cout << "Debit amount exceeded account balance"; }
private:
double currentBalance;
};
derived class
#include "Account.hpp"
#include <string>
class SavingsAccount : public Account {
double Balance;
public:
SavingsAccount(double initBalance, double initInterestRate) {
InterestRate = initInterestRate;
Balance = initBalance;
};
~SavingsAccount() { };
void CalculateInterest(Account& ac, double InterestRate) {
ac.getBalance *= InterestRate;
};
private:
double InterestRate;
};
main program
#include "SavingsAccount.hpp"
int main() {
Account account(75.00);
SavingsAccount savings(100.00, 2.5);
cout << "Current Balance:" << account.getBalance();
return 0;
}