Мне нужно создать тривиальный класс, который имеет несколько подклассов, и у одного из этих подклассов есть собственный подкласс.
AccountClass.h
#ifndef Account_h
#define Account_h
class Account{
public:
//Account(){balance = 0.0;}; Here's where the problem was
Account(double bal=0.0){ balance = bal;};
double getBal(){return balance;};
protected:
double balance;
};
#endif
SavingsAccount.h
#ifndef SavingsAccount_h
#define SavingsAccount_h
#include "AccountClass.h"
class SavingsAccount : public Account{
public:
//SavingsAccount(); And here
SavingsAccount(double bal = 0.0, int pct = 0.0){ balance = bal; rate = pct; } : Account(bal);
void compound(){ balance *= rate; };
void withdraw(double amt){balance -= amt;};
protected:
double rate;
};
#endif
CheckingAccount.h
#ifndef CheckingAccount_h
#define CheckingAccount_h
#include "AccountClass.h"
class CheckingAccount : public Account{
public:
//CheckingAccount(); Here also
CheckingAccount(double bal = 0.0, double lim = 500.0, double chg = 0.5){ balance = bal; limit = lim; charge = chg;} : Account(bal);
void cash_check(double amt){ balance -= amt;};
protected:
double limit;
double charge;
};
#endif
TimeAccount.h
#ifndef TimeAccount_h
#define TimeAccount_h
#include "SavingsAccount.h"
class TimeAccount : public SavingsAccount{
public:
//TimeAccount(); ;)
TimeAccount(double bal = 0.0, int pct = 5.0){ balance = bal; rate = pct;} : SavingsAccount(bal,pct);
void compound(){ funds_avail += (balance * rate); };
void withdraw(double amt){funds_avail -= amt;};
protected:
double funds_avail;
};
#endif
Я продолжаю получать сообщения о том, что определены конструкторы по умолчанию, а также все переменные, которые не существуют ...
Справка!
Редактировать:
Исправлен препроцессор ifndef's
Также это было решено.Спасибо @Coincoin!