Linker Error "undefinied reference to" Encounter::enemy

Hey guys,

Sadly I can't get along a Linker Error here. I don't even known why. I added all files to my project so they compile - did nothing new with Encounter.h and Encounter.hpp - same procedure like always. But now it throws a linker error message.


main.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
// KI Projekt 2.0 (c) Patrick Höfer


#include <fstream>
#include <iostream>
#include <string>
#include "Controls.h"
#include "Screen_output.h"
#include "Encounter.h"


using namespace std;



	
int main()
{
	
	

	draw.create_field("field.txt");
	draw.screen("title.txt");
	
	for(;;)
	{
		int x = ctrl.choose();
		
		if (x == 1)
		{
			(system("CLS"));
			for(;;)
			{
				draw.field();
			}
		}
		else
			std::cout << "Diese Option ist nicht möglich";
	}
	
		
	
	
	
	
	



    system("PAUSE");
    return EXIT_SUCCESS;
}



Encounter.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef Encounter_h
#define Encounter_h


class Encounter
{
	public:
	void enemy();
};

extern Encounter enc;



#endif  



Encounter.hpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <fstream>
#include <string>
#include "Screen_output.h"
#include "Controls.h"
#include "Encounter.h"


Encounter enc;

void Encounter::enemy()
{
	draw.screen("enemy.txt");
}



I hope its not just a trivial error that I didn't managed to find here :(
It could be originating from the files you haven't shown us i.e. "Controls" and/or "Screen_output". Your compiler should tell you.
and can you explain what you're doing on line 11 of your header file?
Last edited on
Did you mean to call it Encounter.cpp instead of .hpp? That might be causes the problem as well.
hm - as I renamed it to .cpp it works - I thought there wouldn't be an issue with .hpp and .cpp since they are both source files? What are the differences?
.hpp is considered a header file and won't get compiled. It's meant to be included like a .h file.

Only .cpp files gets compiled. File extensions recognized as source files vary by implementation. e.g. Some compilers recognize .cxx files also.
Topic archived. No new replies allowed.