how can i solve this error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tayabur Rahman
    New Member
    • Dec 2010
    • 2

    #1

    how can i solve this error?

    #include<iostre am>
    using namespace std;

    class account
    {
    protected:
    char name[40];
    int account_id;
    int account_type;
    float initial_deposit ;
    public:

    float withdraw;
    float balance;
    account();
    void deposit()
    {
    float deposit;
    cout<<"Enter Amount To DEPOSIT:"<<endl ;
    cin>>deposit;
    balance+=deposi t;
    cout<<"Balance is: $"<<balance<<en dl;
    }
    virtual void withdraw()=0;
    };

    account::accoun t()
    {
    cout<<"Enter Account Holder Name:"<<endl;
    cin>>name;
    cout<<"Enter Account ID"<<endl;
    cin>>account_id ;
    cout<<"Enter ACCOUNT TYPE (DEBIT=1,CREDIT =2)"<<endl;
    cin>>account_ty pe;
    cout<<"Enter Initial Deposit"<<endl;
    cin>>initial_de posit;
    balance+=initia l_deposit;
    }

    class debit:public account
    {
    void deposit();

    void withdraw()
    {
    //float withdraw;
    cout<<"Enter Amount To WITHDRAW:"<<end l;
    cin>>withdraw;
    if(withdraw<=ba lance)
    {
    amount-=withdraw;
    cout<<"Balance is: $"<<balance<<en dl;
    }
    else
    {
    cout<<"withdraw failed"<<endl;
    cout<<"Balance Is: $"<<balance<<en dl;
    }
    }
    };

    class credit:public account
    {

    void deposit();
    /*{
    cout<<"Enter Amount To DEPOSIT:"<<endl ;
    cin>>deposit;
    balance+=deposi t;
    cout<<"Balance is: $"<<balance<<en dl;
    }*/
    void withdraw()
    {
    //float withdraw;
    int credit_limit=20 00;
    cout<<"Enter Amount To WITHDRAW:"<<end l;
    cin>>withdraw;
    if(withdraw<=(-credit_limit))
    {
    balance-=withdraw;
    cout<<"Balance is: $"<<balance<<en dl;
    }
    else
    {
    cout<<"withdraw failed"<<endl;
    cout<<"Balance Is: $"<<balance<<en dl;
    }
    }
    };

    int main()
    {
    int account_type=0;
    cout<<"Start"<< endl;
    account ob1;
    debit ob2;
    credit ob3;

    account *p;
    if(account_type =1) p=&ob2;
    else if(account_type =2) p=&ob3;
    else cout<<"Invalid Input For ACCOUNT TYPE"<<endl;

    p->deposit();
    p->withdraw();
    return 0;
    }
  • Tayabur Rahman
    New Member
    • Dec 2010
    • 2

    #2
    error C2040: 'withdraw' : 'void (void)' differs in levels of indirection from 'float'

    Comment

    • Robert Kulseth
      New Member
      • Dec 2010
      • 2

      #3
      I found a few problems with your code. The main problem is you have a name collision. You have a method withdraw and a public member variable withdraw in the same class. it's a good practice to prefix all your member variables with either an '_' or an 'm_'. This will fix most of your problems. you had two other errors that were pretty simple to fix. I compiled it on g++, but didn't run it. Also, you should encapsulate your member variables rather than expose them public. That way no one has to see your ugly 'm_' prefix for member variables. Good Luck.

      Comment

      Working...