We help IT Professionals succeed at work.
Get Started

static field problems

oggiemc
oggiemc asked
on
323 Views
Last Modified: 2012-08-13
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

Comment
Watch Question
Senior Software Engineer (Avast)
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE