lnk2019 error

Problem solved! thanx guys. i can't believe i made such as dumb mistake


Hello cplusplus forums. i am having a problem with this code. i am getting these two errors:

1>testProgram.obj : error LNK2019: unresolved external symbol "public: int __thiscall die::getNum(void)const " (?getNum@die@@QBEHXZ) referenced in function _main
1>testProgram.obj : error LNK2019: unresolved external symbol "public: __thiscall die::die(void)" (??0die@@QAE@XZ) referenced in function _main
1>c:\users\garry\documents\visual studio 2010\Projects\testProgram\Debug\testProgram.exe : fatal error LNK1120: 2 unresolved externals

i just wanted to test separating classes from the main file and i did exactly what my textbook did, but i seem to keep on getting these errors. i have searched the forums the suggestions didn't seem to really help. also i am using visual studio 2010.

here is my code:

die.h
1
2
3
4
5
6
7
8
9
class die
{
	public:
		die();
		int roll();
		int getNum() const;
	private:
		int num;
};



dieImplementation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include "die.h"

using namespace std;

die::die()
{
	num = 1;
	srand(time(0));
}

int die::roll()
{
	num = rand() % 6 + 1;
	return num;
}

int die::getNum() const
{
	return num;
}


testProgram.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include "die.h"

using namespace std;

int main()
{
	die die1;
	cout<<die1.getNum()<<endl;

	return 0;
}
Last edited on
It looks like file dieImplementation.cpp was not included in the project.
Make sure all the files are added to your project. It looks like it doesn't link with the dieImplementation.cpp code.
Topic archived. No new replies allowed.