Link to home
Start Free TrialLog in
Avatar of oggiemc
oggiemcFlag for Ireland

asked on

static field problems

Hello all,

Im getting the following error for the attached code..I believe line 28 in the code is causing the problems..

PersonProblem_09_3a.cpp:28: error: extraneous `int' ignored
PersonProblem_09_3a.cpp:28: error: conflicting declaration 'Account Account::nextAccountNumber'
PersonProblem_09_3a.cpp:12: error: 'Account::nextAccountNumber' has a previous declaration as `int Account::nextAccountNumber'

PersonProblem_09_3a.cpp:54: error: no `void Account::dislplay()' member function declared in class `Account'
PersonProblem_09_3a.cpp: In member function `virtual bool Account::makeWithdrawal(float&)':
PersonProblem_09_3a.cpp:64: error: stray '`' in program
PersonProblem_09_3a.cpp: In constructor `CurrentAccount::CurrentAccount(float, std::string, float)':
PersonProblem_09_3a.cpp:72: error: class `CurrentAccount' does not have any field named `balance'
PersonProblem_09_3a.cpp:72: error: class `CurrentAccount' does not have any field named `owner'
make.exe: *** [PersonProblem_09_3a.o] Error 1

Execution terminated


Someone help please?

Thanks
#include <iostream>
#include <string>

using namespace std;

class Account
{
 protected:
  float balance;
  int accountNumber;
  string owner;
  static int nextAccountNumber;
  
 private:
  void construct(float, string);

 public:
  Account(float, string);
  Account(float);
  Account();
  
  virtual void display();
  virtual bool makeWithdrawal(float &);
  virtual void makeLodgement(float &);
  
} 
  
  int Account::nextAccountNumber = 12345;
   
class CurrentAccount: public Account
{
  float overdraftLimit;
  
 public:
  CurrentAccount(float, string, float);
  CurrentAccount(Account, float);
  virtual void display();
  virtual bool makeWithdrawal(float &);
};

 Account::Account(float _balance, string _owner):balance(_balance),
   owner(_owner){}
   
  Account::Account(float _balance):balance(_balance){}
  
  Account::Account(){}
  
  void Account::construct(float _balance, string _owner){
       accountNumber = nextAccountNumber++;
       balance = _balance;
       owner = _owner;      
       }
       
  void Account::dislplay(){
       cout<<"Account owned by " << owner << " , account number: " 
       << accountNumber << " , balance : " << balance << endl;
       }
       
  bool Account::makeWithdrawal(float& amount){
       if (balance > amount){
           balance = balance - amount;
           return true;}
       else   
           return false;`
       }
  
  void Account::makeLodgement(float& amount){
       balance = balance + amount;
       }

  CurrentAccount::CurrentAccount(float _balance, string _owner, 
  float _overdraftLimit):balance(_balance), owner(_owner), overdraftLimit
  (_overdraftLimit){}
  
  CurrentAccount::CurrentAccount(Account a, float _overdraftLimit):
                  Account(a), overdraftLimit(_overdraftLimit){}
                  
  void CurrentAccount::display(){
    Account::display();
    cout << "And overdraft limit: " << overdraftLimit << endl;}
     
  bool CurrentAccount::makeWithdrawal(float &amt){
       if (amt<=(balance+overdraftLimit)){
           balance-=amt;
           return true;}
           
       else return false;
}

int main()
{
  Account a(100.0f, "Derek Molloy");
  CurrentAccount b(200.0f, "John Doe", 500.0f);
  CurrentAccount c(a, 1000.0f);
  a.display();
  b.display();
  c.display();
  system("pause");
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You forgot the ; at the end of the Account class definition:
class Account {
    // <SNIP>
};                              // <--- this one

Open in new window

heh :)
Avatar of oggiemc

ASKER

Thanks guys..