我无法解决"未解决的外部"

时间:2016-05-08 22:00:01

标签: c++

1>game.obj : error LNK2001: unresolved external symbol "public: bool __cdecl GameStore::loadFromXml(void)" (?loadFromXml@GameStore@@QEAA_NXZ)
1>protocolgame.obj : error LNK2001: unresolved external symbol "public: struct StoreCategory * __cdecl GameStore::getStoreCategoryByName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getStoreCategoryByName@GameStore@@QEAAPEAUStoreCategory@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\Slavi Dodo\Documents\GitHub\forgottenserver\vc14\x64\Release\theforgottenserver.exe : fatal error LNK1120: 2 unresolved externals

我很困惑!我甚至不理解错误的原因。

这是宣言&#34; gamestore.h&#34;

#ifndef FS_GAMESTORE_H_ADCAA356C0DB44CEBA994A0D678EC92D
#define FS_GAMESTORE_H_ADCAA356C0DB44CEBA994A0D678EC92D
struct StoreOffer {
    StoreOffer(uint32_t id, uint32_t thingId, uint8_t addon, uint32_t price, uint8_t type, uint8_t state, std::string name, std::string description, std::vector<std::string> icons)
        : id(id), thingId(thingId), addon(addon), price(price), type(type), state(state), name(name), description(description), icons(icons) {}

    uint32_t id;
    uint32_t thingId;
    uint32_t price;
    uint8_t type;
    uint8_t state;
    uint8_t addon;
    std::string name;
    std::string description;
    std::vector<std::string> icons;
};

struct StoreCategory
{
    StoreCategory(std::string name, std::string description, std::vector<std::string> icons, std::vector<StoreOffer> offers)
        : name(name), description(description), icons(icons), offers(offers) {}

    std::string name;
    std::string description;
    std::string parentCategory;
    std::vector<std::string> icons;
    std::vector<StoreOffer> offers;
};

class GameStore
{
    public:
        bool reload();
        bool loadFromXml();
        StoreOffer* getStoreItemById(uint32_t id);
        StoreCategory* getStoreCategoryByName(const std::string& name);

        const std::vector<StoreCategory>& getStoreCategories() const {
            return storeCategories;
        }

        bool enabled;
        std::vector<StoreCategory> storeCategories;
};

#endif

这就是定义&#34; gamestore.cpp&#34;

#include "otpch.h"

#include "gamestore.h"

#include "pugicast.h"
#include "tools.h"

bool GameStore::reload()
{
    storeCategories.clear();
    return loadFromXml();
}

bool GameStore::loadFromXml()
{
    return true;
}

StoreOffer* GameStore::getStoreItemById(uint32_t id) {
    for (auto it : storeCategories) {
        for (auto item : it.offers) {
            if (item.id == id) {
                return &item;
            }
        }
    }
    return nullptr;
}

StoreCategory* GameStore::getStoreCategoryByName(const std::string& name) {
    auto it = std::find_if(storeCategories.begin(), storeCategories.end(), [name](StoreCategory& storeCategory) {
        return storeCategory.name == name;
    });
    return it != storeCategories.end() ? &*it : nullptr;
}

我已经阅读了有关错误的更多信息,但甚至没有找到解决方案。 当你看到&#34; loadFromXml&#34;只是回归真实,不接受任何论点以及公开,这个问题非常混乱!

1 个答案:

答案 0 :(得分:0)

检查是否正在编译gamestore.cpp!

如果没有将其添加到CLCompile列表中的 projectname .vcproj。