为什么会收到此错误? “未解析的外部符号” [英] Why am I getting this error ? "unresolved external symbol"

查看:189
本文介绍了为什么会收到此错误? “未解析的外部符号”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直得到的错误,我一直在努力弄清楚如何解决它,但失败。我问,是否有人可以指出我的正确方向。

This is the error I have been getting the whole time and I've been trying to figure out how to fix it but have failed. I am asking if anyone can point me to the right direction.

 WorldServer fatal error LNK1120: 2 unresolved externals
WorldServer error LNK2019: unresolved external symbol "public: class CItemElem * __thiscall CLinkedItemMgr::GetLinkedItem(unsigned long)" (?GetLinkedItem@CLinkedItemMgr@@QAEPAVCItemElem@@K@Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem@CDPSrvr@@AAEXAAVCAr@@KKPAEK@Z)
WorldServer error LNK2019: unresolved external symbol "public: int __thiscall CLinkedItemMgr::AddLinkedItem(class CItemElem *)" (?AddLinkedItem@CLinkedItemMgr@@QAEHPAVCItemElem@@@Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem@CDPSrvr@@AAEXAAVCAr@@KKPAEK@Z)

这是.h

#ifndef __ITEM_LINK__H
#define __ITEM_LINK__H
class CLinkedItemMgr
{
private:
    CLinkedItemMgr(){ m_dwLinkedItemCount = 0;};
    ~CLinkedItemMgr(){};
    DWORD m_dwLinkedItemCount;
public:
    map<DWORD,CItemElem*> m_mapLinkedItems;

    static CLinkedItemMgr *GetInstance()
    {
        static CLinkedItemMgr instance;
        return &instance;
    }
    int AddLinkedItem(CItemElem *pItem);
    CItemElem *GetLinkedItem(DWORD dwIndex);
};
#endif

这是.cpp

 #include "stdafx.h"
#include "ItemLink.h"
int CLinkedItemMgr::AddLinkedItem(CItemElem *pItem)
{
    if(!pItem)
        return 0;
    m_mapLinkedItems.insert(make_pair<DWORD,CItemElem*>(++m_dwLinkedItemCount,pItem));
    return m_dwLinkedItemCount;
}
CItemElem *CLinkedItemMgr::GetLinkedItem(DWORD dwIndex)
{
    map<DWORD,CItemElem*>::iterator it = m_mapLinkedItems.find(dwIndex);
    if(it == m_mapLinkedItems.end())
        return FALSE;
    return it->second;
}


推荐答案

这里。

#ifdef __ITEM_LINK
#include "ItemLink.h"

#ifdef __ITEM_LINK 表示如果 __ ITEM_LINK 定义为

在您的情况下,未定义。它仅在包含ItemLink.h时才定义,并且只有包含ItemLink.h已定义。

And in your case, it is not defined. It only gets defined when "ItemLink.h" is included, and "ItemLink.h" only gets included if it's already defined. You've prevented either from happening first.

删除 #ifdef 行。

这篇关于为什么会收到此错误? “未解析的外部符号”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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