LNK 2019 Error

I'm making a text based game and I ran into this error and I do not know what is causing it, please help:

Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Basic::Welcome(void)" (?Welcome@Basic@@QAEXXZ) referenced in function _main C:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text\main.obj Robot Masters - Text
Error 2 error LNK2019: unresolved external symbol "public: void __thiscall Basic::FunctionCaller(void)" (?FunctionCaller@Basic@@QAEXXZ) referenced in function _main C:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text\main.obj Robot Masters - Text
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall Basic::AutoSave(void)" (?AutoSave@Basic@@QAEXXZ) referenced in function _main C:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text\main.obj Robot Masters - Text
Error 4 error LNK1120: 3 unresolved externals C:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text\Debug\Robot Masters - Text.exe 1 1 Robot Masters - Text

Here is my code that i have written (the files included do exist they do not contain anything at the minute)

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "basic.h"
#include "quest.h"
#include "shop.h"
#include "workshop.h"


int main()
{
	Basic b;

	b.Welcome();
	b.FunctionCaller();
	b.balance = 1254;
	b.AutoSave();

	std::cout << "" << std::endl; // Testing only
	system("pause"); // Testing only

	return 0;
}


basic.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
  #include "basic.h"


Basic b;

int GetBalance()
{
	std::ifstream save("save.txt");
	int newBalance;

	save >> newBalance;

	return newBalance;
}

void Welcome()
{
	b.balance = GetBalance();
	std::cout << "Welcome to Robot Masters" << std::endl;
	std::cout << "Balance: $" << b.balance << std::endl;

	return;
}

void FunctionCaller()
{
	// TODO
}

void Help()
{
	std::ifstream HelpFile("help.txt");
	std::string line;

	while (getline(HelpFile, line))
	{
		std::cout << line << std::endl;
	}

	std::cout << "" << std::endl;
	FunctionCaller();
}

void AutoSave()
{
	std::ofstream save("save.txt");

	save << b.balance;

	return;
}

void ShowInventory()
{
	// TODO
}


basic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>

class Basic
{
public:
	int balance;

	void Welcome();
	void FunctionCaller();
	void Help();
	int GetBalance();
	void AutoSave();
	void ShowInventory();
};
In basic.cpp, you've defined Welcome(), FunctionCaller(), etc, to be free functions, rather than methods of your Basic class.
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Basic::Welcome(void)" (?Welcome@Basic@@QAEXXZ) referenced in function _main C:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text\main.obj Robot Masters - Text

The main() calls Basic::Welcome() -- the member function Welcome() of class Basic, but no included object file or library contains implementation for the function.

Same in shorter example:
1
2
3
4
5
6
7
8
9
10
11
12
13
struct Foo {
  int bar();
};

int main() {
  Foo x;
  int y = x.bar();
  return y;
}

int bar() {
  return 42;
}

There are no compiler errors. Line 7 calls member bar() of object x. Object x has type Foo, and definition of Foo on lines 1-3 declares Foo::bar(). The standalone bar() on lines 11-13 is selfconsistent too.

The linker, however, fails to connect the call on line 7 to any implementation. The problem is on line 11. The int bar() is a standalone function and has nothing to do with the member of Foo -- int Foo::bar().

Adding this will solve the problem:
1
2
3
int Foo::bar() {
  return 7;
}

The standalone bar() is never called, but that is not an error.
thanks so much guys, it is all fixed now. Cheers
Topic archived. No new replies allowed.