首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visual Studio 2008 -错误C2872:'NPC‘:不明确的符号

Visual Studio 2008 -错误C2872:'NPC‘:不明确的符号
EN

Stack Overflow用户
提问于 2016-10-18 18:55:26
回答 1查看 376关注 0票数 3

我尝试纠正代码中的最后一个错误。我已经把VS6.0.0移植到VS2008了。

我的最后一个错误在我的SimpleNPC.cpp文件中:

代码语言:javascript
复制
.\SimpleNPC.cpp(216) : error C2872: 'NPC' : ambiguous symbol
    could be '.\SimpleNPC.cpp(30) : NPC_Editor::NPC `anonymous-namespace'::NPC'
    or       'c:\documents and settings\t411\bureau\serveur\server_rc15g\t4c server\NPC_Editor/NPC.h(27) : NPC_Editor::NPC'

这里的错误代码是:

代码语言:javascript
复制
case InsSendSoldItemList:{
    std::list< NPC::SoldItem > itemList;
    std::list< NPC::SoldItem >::iterator i;
    npc->theNpc->GetSoldItemList( itemList );
    CreateItemList
        for( i = itemList.begin(); i != itemList.end(); i++ ){
            AddBuyItem( (*i).price, Unit::GetIDFromName( (*i).itemId.c_str(), U_OBJECT, TRUE ) )
        }
    SendBuyItemList

文件的开头为:

代码语言:javascript
复制
// SimpleNPC.cpp: implementation of the SimpleNPC class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TFC Server.h"
#include "SimpleNPC.h"
#include "NPCMacroScriptLng.h"

#undef Command

#include "NPC_Editor/NPC.h"
#include "NPC_Editor/Keyword.h"
#include "NPC_Editor/Command.h"
#include "NPC_Editor/IfFlow.h"
#include "NPC_Editor/Assign.h"
#include "NPC_Editor/ForFlow.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif


using namespace NPC_Editor;

namespace{
    typedef list< Instruction * > InstructionList;
    typedef NPC_Editor::NPC NPC;

};

在此文件中,我们可以找到以下代码:

代码语言:javascript
复制
std::list< NPC_Editor::NPC::SoldItem > soldItems;

你知道为什么会有冲突吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-10-18 19:04:04

代码语言:javascript
复制
using namespace NPC_Editor;

namespace{
    typedef list< Instruction * > InstructionList;
    typedef NPC_Editor::NPC NPC;
};

首先请注意,在名称空间的右大括号中不需要使用;

using namespace NPC_Editor;使得可以从全局范围内访问NPCtypedef NPC_Editor::NPC NPC;在匿名名称空间中声明了一个名称NPC,因此可以从全局作用域访问。

您的问题就是编译器所说的:一个名称有两个可能的符号,这是不明确的。删除你的typedef应该可以解决这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40106323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档