错误LNK2019:函数中引用的未解析的外部符号方法

时间:2013-11-04 21:10:39

标签: c++ unresolved-external

这是我的问题错误报告:

Error   2   error LNK2019: unresolved external symbol 
"public: int __thiscall item::getSubstanceDurability(enum myEnums::MATERIAL)" (?getSubstanceDurability@item@@QAEHW4MATERIAL@myEnums@@@Z) referenced in function 
"public: virtual void __thiscall armor::setHardness(enum myEnums::MATERIAL,int)" (?setHardness@armor@@UAEXW4MATERIAL@myEnums@@H@Z)  
C:\Users\Raenir Salazar\My Projects\COMP345_Assignment2\COMP345_Assignment2\armor.obj   COMP345_Assignment2

当我正在尝试编译时发生。 这是我的代码:

Items.cpp

int getSubstanceHardness ( MATERIAL substance ) {
    switch (substance) {
    case 0:
        return 0;
        break;
    case 1:
        return 0;
        break;
    case 2:
        return 0;
        break;
    case 3:
        return 1;
        break;
    case 4:
        return 0;
        break;
    case 5:
        return 2;
        break;
    case 6:
        return 5;
        break;
    case 7:
        return 8;
        break;
    case 8:
        return 10;
        break;
    case 9:
        return 15;
        break;
    case 10:
        return 20;
        break;
    case 11:
        return 5;
        break;
    default:
        return 0;
        break;

    }
}

Items.h

int getSubstanceDurability ( MATERIAL );

装甲。 h& armor.cpp

class armor: public item {
    protected:
        int armorClass;
        int armorCheckPenalty;
        double arcaneSpellFailure;
        int maxDEXBonus;
        int speedPenalty;
        CHARACTER_ARMOR armorType;
    public:
        armor();
        armor( int, int, double, string, int, int, double, double, 
            CHARACTER_ARMOR, SIZE, MATERIAL, int /*+X*/ );

        int getArmorClass ();
        void setArmorClass ( int );
        int getArmorCheckPenalty ();
        void setArmorCheckPenalty( int );
        double getArcaneSpellFailure ();
        void setArcaneSpellFailure ( double );
        //void setArmorName ( string );
        int getMaxDEXBonus ();
        void setMaxDEXBonus ( int );
        int getspeedPenalty ();
        void setspeedPenalty ( int );
        CHARACTER_ARMOR getArmorType();
        void setArmorType( CHARACTER_ARMOR );
        void setDurability( MATERIAL, int /*AC*/, int /* +X */, SIZE );
        void setHardness( MATERIAL, int /* enhancement */ );
};

void armor::setHardness( MATERIAL substance, int enhancement ) {
    int substanceDensity; 
    substanceDensity = this->getSubstanceDurability( substance );
    int density;
    density = substanceDensity + (enhancement * 2);

    this->hardness = density;

    //this->hardness = ((this->getSubstanceDurability(substance)) + (enhancement * 2));
}

enum.h

#ifndef ENUM_H
#define ENUM_H

namespace myEnums
{
        enum CHARACTER_CLASS
        {
            FIGHTER, CLERIC, WIZARD,
            ROGUE, DRUID, RANGER, BARD,
            SORCERER, PALADIN

        };
        enum CHARACTER_WEAPON
        {
            NOTHING, LONGSWORD, SHORTSWORD, KATANA, AMMUNITION, GRAPPLE, RAY
        };
        enum WEAPON_CATEGORY 
        {
            SIMPLE, MARTIAL, EXOTIC,
        };
        enum WEAPON_SUBCATEGORY
        {
            UNARMED, LIGHT_MELEE, ONE_HANDED_MELEE, TWO_HANDED_MELEE, RANGED
        };
        enum CHARACTER_ARMOR
        {
            UNARMORED, CHAINMAIL, PADDED
        };
        enum CHARACTER_SHIELD
        {
            NONE, BUCKLER, LIGHT_WOODEN, LIGHT_STEEL, HEADY_WOODEN,
            HEAVY_STEEL, TOWER
        };
        enum CHARACTER_RACE
        {
            HUMAN, ELF, DROW, HALFLING,
            DWARF, GNOME
        };
        enum SIZE
        {
            FINE, DIMINUTIVE, TINY, SMALL, 
            MEDIUM, LARGE, HUGE, GARGANTUAN, 
            COLOSSAL, COLOSSAL_P, COLOSSAL_PP
        };
        enum DAMAGE_TYPE
        {
                // This one is tricky, some weapons
                // Can have multiple damage types...
            BLUDGEONING, SLASHING, PIERCING
        };
        enum MATERIAL
        {
            PAPER, CLOTH, ROPE, GLASS, ICE, LEATHER, WOOD,
            STONE, METAL, MITHRAL, ADAMANTINE, SOFT_METALS
        };
        enum BAB_PROGRESSION 
        {
            HIGH, MID, LOW
        };
        enum SAVING_THROW
        {
            HIGH_SAVE, LOW_SAVE
        };
};

不知道出了什么问题,我一直在试图摆弄重载和签名,仔细检查数据类型,但没有任何实际的语法错误,据我所知,尽我所知。

1 个答案:

答案 0 :(得分:1)

事实证明我在我的一个功能上冒了一个错误的名字,我很惊讶它甚至编译得那么远。对不起,我无法提供给我答案的人。

getSubstanceHardness被误称为getSubstanceDurability。