未定义对' Class :: Class'的引用 [英] Undefined reference to 'Class::Class'

查看:59
本文介绍了未定义对' Class :: Class'的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决上一个问题后(请参阅我提出的另一个问题).我已经宣布了更多的课程.

After fixing the previous problem (see my one other question that I have asked). I had declared more classes.

其中之一称为 CombatAdmin ,它可以执行各种操作:(头文件)

One of these is called CombatAdmin which does various things: (Header file)

#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 文件的片段)

It is then instanced in the main.cpp file like this: (Snippet of the main.cpp file)

#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

但是,当我尝试编译项目时,出现以下错误:

However, when I try to compile the project, I get the following error:

C:\Documents and Settings\James Moran.HOME-B288D626D8\My Documents\C++ projects\Test Project\main.cpp|59|undefined reference to `CombatAdmin::CombatAdmin()'|

我在GNU GCC编译器中使用Code :: Blocks IDE(版本10.05).该项目的类型为控制台应用程序".我正在使用Windows XP 32位SP3.

I am using the Code::Blocks IDE (ver 10.05), with the GNU GCC compiler. The project is of type "Console application". I am using windows XP 32 bit SP3.

我尝试更改搜索目录以包含目标文件所在的位置,但是在那里没有成功.

I have tried changing to search directories to include where the object files are, but no success there.

叙述者和 PIbot 被很好地实例化.(然后使用,未显示)

As can be seen from the code, the narrator and PIbot are instanced just fine. (then used, not shown)

因此,我的问题是,我该怎么做才能阻止这些错误的发生?当我在使用库之前遇到类似的"x的未定义引用"错误时.我只是忘了在Code :: Blocks中链接到它们,一旦我这样做,它们就会起作用.

My question is, therefore, what do I need to do to stop these errors occurring? As when I encountered similar "Undefined reference to x" errors before using libraries. I had just forgotten to link to them in Code::Blocks and as soon as I did, they would work.

由于这堂课是我自己做的,因此我对此不太确定.

As this class is of my own making I am not quite sure about this.

请说出您是否需要有关代码等的更多信息.

Do say if you need more information regarding the code etc.

推荐答案

您已经声明了默认构造函数(CombatAdmin()),因此阻止了编译器自动生成它.因此,您需要1)从类中删除默认构造函数的声明,或2)提供实现.

You have declared the default constructor (CombatAdmin()) and thus prevented the compiler from automatically generating it. Thus, you either need to 1) remove declaration of the default constructor from the class, or 2) provide an implementation.

这篇关于未定义对&amp;#39; Class :: Class&amp;#39;的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆