0

I'm still new to C++ and working out this assignment.

When I attempt to call the various functions, I'm informed that "bank isn't defined."

class bankAccount {
    private:
        float bank[10];
    public:
        void deposit (int num, float value);
        void balance (int num);
        void withdraw (int num, float value);
        void transfer (int num1, int num2, int value);
}; // end class

void deposit (int num, float value){
    bank[num] += value;
}

bankAccount.h:16:37: error: 'bank' was not declared in this scope

1
  • 1
    deposit function isn't part of bankAccount interface and can't have access to it's private members. Moreover it doen't have even object of bankAccount class to even try access to bank array. To sum up, u're trying to access the variable in wrong scope(u're using it in score of global defined function deposit(int,float) while float bank[] is in score of bankAccount class Commented Sep 13, 2019 at 21:02

2 Answers 2

4
void deposit (int num, float value){
    bank[num] += value;
}

defines a free function.

You need

void bankAccount::deposit (int num, float value){
    bank[num] += value;
}
Sign up to request clarification or add additional context in comments.

Comments

1

void deposit(int num, float value) is a free function, however :

void bankAccount::deposit (int num, float value){
    bank[num] += value;
}

Is the definition of the member function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.