1

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I have a game program and I am getting VERY frustrated. Everything was running fine, and I decided to clean up my program by making separate files for each set of functions. The code is very long with multiple files, but heres the basic idea:

Im on Windows XP using the Code::Blocks IDE

In my entity.h Ive declared all of my functions and variables for that class. In my entity.cpp Ive included it, as well as in all my other files. But Im still getting a huge list of errors that tell me I have an undefined reference to all of the methods in entity.h as well as all my other header files. For example, I have a function call print() to make it easier to print out things, and thats the first method I call from the entity.h file. I get this error:

Heres the code for print():

void print(string f) {
 cout<<f<<endl;
} 

How Im calling it:

void Player::win(){
entity e;
e.print("You have defeated the orc");

} The error:

In function 'ZN6Player3winEv': undefined reference to 'entity::print(std::string)'

And yes, I do have an object of entity. Its also happening for every single other function in the entity class and file.

Community
  • 1
  • 1
CMP6LG
  • 83
  • 1
  • 3
  • 13

2 Answers2

2
void print(string f) {
 cout<<f<<endl;
} 

should be

void entity::print(string f) {
 cout<<f<<endl;
} 
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • that worked... now I have to figure out why the program is just ending after choosing the difficulty. Ill figure that out though. Thanks for the quick reply. – CMP6LG Oct 13 '12 at 22:30
0
void print(string f) {
 cout<<f<<endl;
} 

is a global function

if you want to call

e.print("You have defeated the orc");

then you need an implementation for

void entity::print(string f)
Adrian Herea
  • 658
  • 6
  • 7