3

I try to correct my last error on my code. I have migrate VS6.0 to VS2008.

My last error is in my SimpleNPC.cpp file:

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

The code for the error here is:

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

the beginning of the file is:

// 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;

};

In this file we can found this code:

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

Do you have any idea why there is conflict? Thank you!

1 Answers1

1
using namespace NPC_Editor;

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

First note that you don't need ; at the closing brace of a namespace.

using namespace NPC_Editor; makes NPC reachable from global scope. typedef NPC_Editor::NPC NPC; declares a name NPC in an anonymous namespace, so reachable from global scope.

Your problem is exactly what the compiler says: you have two possible symbols for a single name, which is ambiguous. Removing your typedef should solve the problem.

rocambille
  • 15,398
  • 12
  • 50
  • 68
  • Or better remove `using namespace` directive and refactor a code. What point in creating namespaces if you are going to ignore them later? – Ari0nhh Oct 18 '16 at 11:08
  • Oh thank you, its perfect! Actually i have just remove my typedef and its very nice! – Fourth Rebirth Oct 18 '16 at 11:31