Help with unresolved external symbol

I keep receiving error messages saying that an unresolved external link is causing my code to crash, I rewrote my first code to cut back a lot of unnecessary lines hoping that would solve it but I still have the same message. It says that the error is in the calling of the factorialClass? I don't know I am knew to this and am having a real difficult time. Any Help would be greatly appreciated


Error 1 error LNK2019: unresolved external symbol "int __cdecl factorial(int)" (?factorial@@YAHH@Z) referenced in function "public: int __thiscall factorialClass::number(void)" (?number@factorialClass@@QAEHXZ)

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include "stdafx.h"
#include <iostream>

using namespace std;

class factorialClass{

	int integer;
	int temp;
	int x;

public:

	factorialClass(int) : integer(x){}
	int number() {
		cout << "Please enter a positive integer: ";
		cin >> integer;
		if (integer < 0)
			cout << "That is not a positive integer. \n";
		else
			cout << integer << "factorial is: " << (integer) << endl;
	
		int factorial(int integer); {
			if (integer <= 1) return 1;
			temp = integer * factorial(integer - 1);
			return temp;
		}
	}
		 

};
	

int _tmain(int argc, _TCHAR* argv[])
{
	factorialClass FactialInstance(3);
	factorialClass FactialInstance2(5);
	factorialClass FactialInstance3(7);

	cout << "The factorial of 3 is: " << FactialInstance.number() << endl;
	cout << "The factorial of 5 is: " << FactialInstance2.number() << endl;
	cout << "The factorial of 7 is: " << FactialInstance3.number() << endl;
	
	return 0;}
Last edited on
"unresolved external symbol" means that the function can't find the definition of the function.

The problem is that you have declared factorial inside the number function. Note the semicolon on line 23. The code that comes (inside {}) is part of the number function. You can't define a function inside another function so you will have to define it elsewhere.
Thank you very much, I can't believe that is all that I was missing haha, any ways thanks for your help.
Topic archived. No new replies allowed.