Mosho
Mosho

Reputation: 7078

C++: undeclared identifier

I have searched quite thoroughly on this but can't seem to find an answer.

I have a "bank" class that naturally has a vector. here is one of the functions with the problematic part:

int bank::open(op *o, int id)
{
account *acc = new account();
if (search(o->account))
    return ACCOUNT_EXISTS;
accounts.push_back(acc->open(o, id));
}

and i get a "syntax error : identifier 'account' and "'acc' : undeclared identifier error.

this .cpp has #include "bank.h" which has #include "bank_account.h" (which is the banks personal account) which has #include "account.h", and there is absolutely no way for a circular reference.

if I type account:: the scope is visible, and if I right click and search for the declaration it (VS 2008) finds it.

here is the account.h class declaration

class account
{
public:
account(void) {}
~account(void) {}

int number;
int password;
int bal;

//void openAccount(op *o, int id);
void deposit(int amount, int id);
int withdraw(int amount, int id);
void balance(int id);
void close(int id);
int comission(float percentage);
void log(int msg, int id, int amount=0);
};

Thanks for any help...

Upvotes: 0

Views: 1193

Answers (3)

DYoung
DYoung

Reputation: 114

Is it possible that some of your headers have the same header guards? It looks like you think a header should be included but it isn't.

So make sure that you don't have

#if !defined( BANK_H )  
#define BANK_H

#endif //BANK_H

Or something similar in multiple files. Each header file should have guards, but not the same ones :)

Upvotes: 0

abelenky
abelenky

Reputation: 64730

First, on this line:

accounts.push_back(acc->open(o, id));

You are calling acc->open(), and acc is of type account*.
But I do not see any definition for method open in class account.
Therefore, you cannot call the open via the acc pointer.

The closest match is the method openAccount, but that is currently commented out, and cannot be used.


Secondly, your code calls accounts.push_back().
But as far as the code you've shown us, bank does not have a member accounts.
You'll need to show us that part too.

Upvotes: 1

thesamet
thesamet

Reputation: 6582

  1. try to include account.h in the cpp file in questions. It's better to include what you use and not to rely on other include files to include things for you.

  2. It seems that you are leaking account objects. They are never freed (regardless if the account exists or not)

Could it be that the account class is in a different namespace?

Upvotes: 0

Related Questions