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

Posted on 2014-08-05
Last Modified: 2014-08-05

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?

Question by:f19l
    1 Comment
    LVL 86

    Accepted Solution

    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


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now