I was coding a simple text based RPG when I came across this error. I use the Code::Blocks IDE, so it should compile it all for me. I'm new to C++ so I couldn't make sense out of all the rather advanced codes getting this same error. Here's the function it occurred in (home_action.cpp):
#include <iostream>
#include "header.h"
using namespace std;
void home_action()
{
cout << "";
cout << "\nYour health: " << health;
cout << "\nYour mana: " << magic;
cout << "\nYour gold: " << gold;
string mov;
if (exp > 99)
{
cout << "\nRest to level up.";
}
else
{
cout << "\nYou have " << exp << "/100 exp.";
string mov;
cout << "\n"<< name << ", you're at home. Do you want to fight, travel, or steal some bread? ";
cin >> mov;
}
if (mov == "rest" and exp > 99)
{
level_up();
home_action();
}
else if (mov == "fight")
{
combat_scene("Guard", 21, 70, 10, 5);
}
else if (mov == "stats")
{
cout << "\n" << strength << " strength.";
cout << "\n" << intel << " intelligence.";
cout << "\n" << sneak << " dexterity.";
home_action();
}
else if (mov == "steal")
{
calculate_roll(sneak, 3);
cout << "\n" << name << ", rolled a "<< die_roll << "!";
if (goal > die_roll)
{
health = max_health;
magic = max_magic;
cout << "\n" << name << " stole a loaf of bread and restored health.";
home_action();
}
else
{
cout << "\n" << name << " got into a fight!";
combat_scene("Goblin", 12, 50, 5, 3);
}
}
else if (mov == "quit")
{
cout << "\nYou took an arrow to the knee and decided to retire from adventuring.";
cout << "Thanks for playing!";
}
else if (mov == "travel")
{
travel_locations();
cout << "\nWhere do you want to travel to?";
cin >> current_town;
location();
}
else
{
cout << "\nYou cannot "<< mov << ".";
home_action();
}
}
This caused the following error:
||=== RPG, Debug ===|
obj\Debug\home_action.o||In function `Z11home_actionv':|
C:\Users\William\Documents\Stuff\Programming\C++\Randomness\RPG\home_action.cpp|64|undefined reference to `travel_locations()'|
C:\Users\William\Documents\Stuff\Programming\C++\Randomness\RPG\home_action.cpp|67|undefined reference to `location()'|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|
The header referenced is (header.h):
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
#include <iostream>
using namespace std;
extern int intel;
extern int strength;
extern int sneak;
extern int damage;
extern int max_health;
extern int max_magic;
extern int enemy_health;
extern int health;
extern int magic;
extern string chosen_class;
extern int die_roll;
extern int goal;
extern int gold;
extern int exp;
extern string name;
extern string current_town;
void level_up();
void calculate_max();
void reset_healths();
void spell();
void attacking_turn();
void home_action();
void calculate_roll(int stat, int difficulty);
void combat_scene(string enemy, int xp_gain, int hp, int dmg, int money);
void location();
int main();
void travel_locations();
#endif // HEADER_H_INCLUDED
And the two functions mentioned in the error are here:
travel_locations():
#include <iostream>
#include "header.h"
using namespace std;
void travel_locations()
{
if (current_town == "1" || current_town == "murthan")
{
cout << "\n2: Worthal";
cout << "\n3: Einbron";
cout << "\n4: Home";
}
else if (current_town == "2" || current_town == "worthal")
{
cout << "\n1: Murthan";
cout << "\n3: Einbron";
cout << "\n4: Home";
}
else if (current_town == "3" || current_town == "einbron")
{
cout << "\n1: Murthan";
cout << "\n2: Worthal";
cout << "\n4: Home";
}
else if (current_town == "4" || current_town == "home")
{
cout << "\n1: Murthan";
cout << "\n2: Worthal";
cout << "\n3: Einbron";
}
}
location():
#include <iostream>
#include "header.h"
using namespace std;
void location()
{
cout << "\n";
if (current_town == "1" || current_town == "murthan")
{
murthan();
}
else if (current_town == "2" || current_town == "worthal")
{
worthal();
}
else if (current_town == "3" || current_town == "einbron")
{
einbron();
}
else if (current_town == "4" || current_town == "home")
{
cout << "\nYou have returned home.";
home_action();
}
else
{
cout << "\nInvalid location. Enter another.";
cin >> current_town;
}
}
I cannot figure out what is causing this. Any help would be greatly appreciated.