После исправления предыдущей проблемы (см. Еще один мой вопрос, который я задал).Я объявил больше классов.
Один из них называется CombatAdmin, который выполняет различные функции: (Заголовочный файл)
#ifndef COMBATADMIN_H
#define COMBATADMIN_H
#include <string> // Need this line or it complains
#include <Player.h>
#include <Sound.h>
#include <Enemy.h>
#include <Narrator.h>
using namespace std;
class Enemy;
class Player;
class CombatAdmin // Code yet to be commented here, will come soon.
{
public:
CombatAdmin();
void healthSet(double newHealth, string playerName);
void comAdSay(string sayWhat);
void playerFindsChest(Player *player,Weapon *weapon,Armour *armour);
void youStoleOurStuffEncounter(Player *player);
void comAdWarning(string enemyName);
void comAdAtkNote(string attack, double damage,string target,string aggresor);
void entDefeated(string entName);
void comAdStateEntHp(string ent, double hp);
void comAdStateScanResults(string enemyName, double enemyHealth);
string doubleToString(double number);
string intToString(int number);
bool isRandEncounter();
void randomEncounter(Player *player,Sound *sound,Narrator *narrator);
bool combatRound(Player *player, Enemy *enemy, Sound *sound, bool ran);
void playerFindsItem(string playerName,string itemName,double itemWeight,double playerWeight);
void playerFindsGold(string playerName,double coinCnt,double playerCoinCnt);
};
#endif // COMBATADMIN_H
Затем он создается в файле main.cpp следующим образом: (Фрагмент файла main.cpp)
#include <iostream> // Required for input and output
#include <Item.h> // Item header file.
#include <Weapon.h> // Header files that I have made for my classes are needed for this program
#include <sstream> // Needed for proper type conversion functions
#include <windows.h> // for PlaySound() and other functions like sleep.
#include <time.h> // Needed to seed the rand() function.
#include <mmsystem.h> // Not sure about this one, possibly defunct in this program.
#include <stdio.h> // Needed for a similar kind of output as iostream for various functions error msgs.
#include <irrKlang.h> // The header file of the sound lib I am using in this program.
#include <Narrator.h> // The narrators's header file.
#include <Pibot.h> // Other header files of classes.
#include <Armour.h>
#include <Player.h>
#include <Weapon.h>
#include <CombatAdmin.h>
using namespace irrklang;
using namespace std;
// Forward referenced functions
void seedRandom(); // Seeds the random number so it will be random as apposed to pseudo random.
string getPlayerName(string temp); // Gets the player's new name.
int main(int argc, char* argv[])
{
// Variables and object pointers declared here.
CombatAdmin *comAd = new CombatAdmin(); // Handles combat.
Narrator *narrator = new Narrator(); // The Narrator that says stuff
Pibot *piebot = new Pibot(); // PIbot, the player's trusty companion
string temp; // Temp string for input and output
Однако, когда я пытаюсь скомпилировать проект, я получаю следующую ошибку:
C:\Documents and Settings\James Moran.HOME-B288D626D8\My Documents\C++ projects\Test Project\main.cpp|59|undefined reference to `CombatAdmin::CombatAdmin()'|
Я использую Code :: BlocksIDE (версия 10.05), с компилятором GNU GCC.Проект относится к типу «Консольное приложение».Я использую 32-разрядную версию SP3 для Windows XP.
Я попытался перейти на каталоги поиска, чтобы указать, где находятся объектные файлы, но безуспешно.
Как видно из кода,Рассказчик и "PIbot" создаются просто отлично.(затем используется, не показан)
Поэтому мой вопрос: что мне нужно сделать, чтобы эти ошибки не возникали?Как, когда я столкнулся с подобными ошибками «Неопределенная ссылка на x» перед использованием библиотек.Я просто забыл ссылаться на них в Code :: Blocks, и как только я это сделаю, они сработают.
Поскольку этот класс - мой собственный, я не совсем уверен в этом.
Скажите, если вам нужна дополнительная информация о коде и т. Д.