2016-10-18 9 views
3

내 코드에서 마지막 오류를 수정하려고합니다. 나는 VS6.0을 VS2008로 마이그레이션했다.Visual Studio 2008 - 오류 C2872 : 'NPC': 모호한 기호

.\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; 

}; 

내 마지막 오류 내 SimpleNPC.cpp 파일에

이 파일에서이 코드를 찾을 수 있습니다 :

std::list<NPC_Editor::NPC::SoldItem> soldItems; 

충돌이있는 이유를 알고 있습니까? 감사합니다.

+0

"헤더 파일은 ..."이라고 작성했지만 .cpp 파일 내용을 붙여 넣었습니다. 관련 콘텐츠를 .cpp와 .h로 모두 붙여 넣으십시오. –

+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을 제거하면 문제가 해결됩니다.

+0

더 나은'using namespace' 지시자와 리팩토링 코드를 제거하십시오. 나중에 무시할 경우 네임 스페이스를 만드는 점은 무엇입니까? – Ari0nhh

+0

오, 감사합니다. 사실 난 그냥 내 typedef 및 그 아주 좋은 제거합니다! –