Is it possible to avoid C++ compiler error (C2757) where 2 different header files contain same symbol for namespace & class?

Posted by dharmendra on Stack Overflow See other posts from Stack Overflow or by dharmendra
Published on 2010-12-30T22:41:42Z Indexed on 2010/12/30 22:54 UTC
Read the original article Hit count: 215

Filed under:

Hi,

I am facing a problem when implementing some new code to an existing library. This library already references a class with a name say 'foo'. The same name is used as a namespace in the other header file which has to be included to implement the new functionality. Since both the header files are a part of legacy code libraries I cannot amend them. So here I am looking for any way so as to avoid the Compiler Error (C2757: a symbol with this name already exists and therefore this name cannot be used as a namespace name). I am not sure whether it is possible or not. Hence, Any help shall be appreciated. Thanks

For clarity here is the sample code illustration for the issue:

HeaderA.h

class foo
{}

HeaderB.h

namespace foo
{
class ABC{}
}

HeaderC.h

#include <HeaderA.h>
#include <HeaderB.h>
using namespace foo;

class Toimplement{
ABC a; //Throws Error C2757
}

© Stack Overflow or respective owner

Related posts about c++