C2039, C3861 / Not a member, Identifier not found

I am very new to C++ and programming in general so please bare with me. Compiling the code below produces 3 errors on Microsoft Visual Studio C++.

//Account.h
class Account
{
public:
Account ( int );
void credit ( int );
void debit ( int );
int getBalance();

private:
int balance;
};

//AccountI.cpp
#include <iostream>
using std::cout;
using std::endl;

#include "Account.h"

Account::Account ( int preBalance )
{
balance = preBalance;
}
void Account::credit ( int preCredit )
{
balance = balance + preCredit;
}
void Account::debit ( int preDebit )
{
balance = balance - preDebit;
}
int Account::getBalance()
{
return balance;
}
void Account::displayMessage()
{
cout << "Balance is: " << getBalance() << endl;
}

//AccountC.cpp
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

#include "Account.h"

int main()
{
int creditAmmount;
int debitAmmount;
Account myAccount (10);

cout << "Enter deposit ammount: ";
cin >> creditAmmount;
myAccount.credit ( creditAmmount );

cout << "Enter withdrawal ammount: ";
cin >> debitAmmount;
myAccount.debit ( debitAmmount );

myAccount.displayMessage();

return 0;
}


ERROR #1...accountc.cpp(24) : error C2039: 'displayMessage' : is not a member of 'Account'...
...account.h(4) : see declaration of 'Account'

EROOR #2... accounti.cpp(25) : error C2039: 'displayMessage' : is not a member of 'Account'...
...account.h(4) : see declaration of 'Account'

ERROR #3...accounti.cpp(27) : error C3861: 'getBalance': identifier not found


I tried the MSDN online help but I got no answers. I do not understand why display message would not be a member of class Account, because I declared displayMessage() in a header file Account.h and linked the header file with accountI.cpp and accountC.cpp using "#include "Account.h"". Furthermore, "displayMessage()" is declared public. I also don't understand why "getBalance" cannot be found because i declared getBalance with return type int and no parameters. I can successfully create the same kind of program with data hiding using strings instead of intergers... so I am thinking I did not declare a standard class int like I would declare #include <string>. Of course, I searched "standard classes" and did not find standard class int. The other problem I can think of is that int might be an invalid return type? therefore "string getBalance(); / return balance" would be valid while "int getBalance(); / return balance" would be invalid. As I stated earlier, the program works fine if i use strings instead of intergers... I am truly stumped :/

1
2
3
4
5
6
7
8
9
10
11
12
13
class Account
{
public:
Account ( int );
void credit ( int );
void debit ( int );
int getBalance();

void displayMessage();

private:
int balance;
};
Code looks good, as pointed out above you just forgot to add the function prototype for displayMessage() to the class header file so the code never makes it to the displayMessage() function definition in AccountI.cpp.

return 0;
:/ such a simple error... i need to learn to debug better. Thank you for the reply.
Last edited on
Topic archived. No new replies allowed.