Why do I keep getting a message stating that a function has not been declared in a class?


I have produced some basic C++ code in which I have a class with declared functions. Below it I have defined those functions but yet when I run the code I get a message stating the the functions have not been delcated in the class. I cannot see any reason why the code should not work. Could you please have a look?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Well, C++ is case sensitive. While you have declöared some methods that start with lowercase letters, you are implementing them with uppercase names. Try

//preprocessor calls...
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

class BankAccount
      private:   //private attributes first...
         int accnumber;
         string accholder;
         float accbalance;
      public:  //followed by public methods
         BankAccount();   //the constructor
         void setAccNumber(int acnumin);
         int getAccNumber();
         void setAccHolder(string acholderin);
         string getAccHolder();
         void setDeposit(float depamnt);
         void setAccBalance(float acamountin);
         float getAccBalance();
         void setWithdrawal(float depamnt);
         float getWithdrawal(float witamnt);

BankAccount::BankAccount()   //constructor sets account balance to zero
                             //when an instance of BankAccount is created
void BankAccount::setAccNumber(int acnumin)   //sets the account number
int BankAccount::getAccNumber()   //returns integer account number
         return accnumber;
void BankAccount::setAccHolder(string accholderin)   //sets account name
string BankAccount::getAccHolder()   //returns name of account number
         return accholder;
void BankAccount::setAccBalance(float acamountin)   //sets the initial account balance
float BankAccount::getAccBalance()    //returns current account balance
      return accbalance;
void BankAccount::setDeposit(float depamnt)   //adds an amount to the account balance
void BankAccount::setWithdrawal(float witamnt)   //subtracts an amount from the account balance
int main()
    //instantiate three objects of bank accounts...
    BankAccount account1, account2, account3;
    //set the account details...
    account1.setAccHolder("Charles Darwin");
    account2.setAccHolder("Michael Faraday");
    account3.setAccHolder("Charles Babbage");
    //display the account details...
    cout<<"\n Account Number 1: "
    cout<<" Account Holder 1: "    
    cout<<" Account Balance 1: "

    cout<<"\n Account Number 2: "
    cout<<" Account Holder 2: "    
    cout<<" Account Balance 2: "
    cout<<"\n Account Number 3: "
    cout<<" Account Holder 3: "    
    cout<<" Account Balance 3: "
    cout<<"\n\t Press any key to close.\n";
    return 0;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.