error LNK2019

I am currently working on an Account login system and when I run the program I receive this error message:

error LNK2019: unresolved external symbol

If you want to see the full code of the source file just ask

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const int NUM_OF_ACCOUNTS = 1;

Account *account = new Account[NUM_OF_ACCOUNTS];

int AccountSearch(int number, string password);

foundAccount = AccountSearch(aNumSearch, passSearch);

			int AccountSearch(int n, string p);
				{
					int x = 0;
					for(; x < NUM_OF_ACCOUNTS; x++)
					{
						if(account[x].getAccNum() == number && 
							account[x].getPassword() == password)
							return x;
					}
						return x;
				}

			if (foundAccount == 0)
			{
				cout << "Your account was not found or you entered"
					"a invalid account number and/or passoword." << endl;
			}
			else
			{
				cout << "You are now logged into your account..." << endl;
				cout << "-------------------------------------" << endl;
			}
Give the full error message, it tells you which symbol is unresolved. It is not related to a specific line of code - rather, it (usually) means that some function hasn't been defined.
Last edited on
Ok, here is the full error message:

error LNK2019: unresolved external symbol "int __cdecl AccountSearch(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"

(?AccountSearch@@YAHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@

@std@@@Z) referenced in function _main
Did you define the AccountSearch function?
Yes would that be this line:

int AccountSearch(int number, string password);

or am I missing something ?
You just declared it, you need to define it also.

1
2
3
4
5
6
int MyFunction(int); // <- declaration

int MyFunction(int param)
{
    return param + 1;
} // <- definition 
is it not this:

1
2
3
4
5
6
7
8
9
10
11
int AccountSearch(int n, string p);
	{
		int x = 0;
		for(; x < NUM_OF_ACCOUNTS; x++)
		{
			if(account[x].getAccNum() == number && 
				account[x].getPassword() == password)
				return x;
		}
			return x;
	}


I also think I should note this is being used in a case switch
Last edited on
1. You can't define a function inside another function
2. That semicolon at the end of the line makes it a declaration, and so the braces with code in them are just more code to execute. Did you not notice that you couldn't use n and p?
Topic archived. No new replies allowed.