我尝试更正我的代码上的最后一个错误。我已将VS6.0迁移到VS2008。
我的上一个错误出现在我的SimpleNPC.cpp文件中:
.\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'
这里的错误代码是:
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
文件的开头是:
// 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;
};
在这个文件中我们可以找到这段代码:
std::list< NPC_Editor::NPC::SoldItem > soldItems;
你知道为什么会有冲突吗? 谢谢!
答案 0 :(得分:1)
using namespace NPC_Editor;
namespace{
typedef list< Instruction * > InstructionList;
typedef NPC_Editor::NPC NPC;
};
首先请注意,您不需要在命名空间的右括号中使用;
。
using namespace NPC_Editor;
使NPC
可以从全局范围访问。 typedef NPC_Editor::NPC NPC;
在匿名命名空间中声明了一个名称NPC
,因此可以从全局范围访问。
您的问题正是编译器所说的:对于单个名称,您有两个可能的符号,这是不明确的。删除typedef
可以解决问题。