Re: UN-using a namespace?
- From: "Heinz Ozwirk" <SPAMhozwirk@xxxxxxxx>
- Date: Mon, 12 Mar 2007 22:36:48 +0100
"Dave Calkins" <david.calkins@xxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:uJt1NTLZHHA.4940@xxxxxxxxxxxxxxxxxxxxxxx
I'm familiar with the "using namespace" to expose the members of a
namespace to the global namespace. Is there a way to UN-use a namespace?
We're calling a third party library which, in its headers has "using
namespace" for its own namespace. This ends up polluting the global
namespace and causing conflicts in our code. For example, the library
defines a CPoint class which, of course conflicts with the MFC CPoint
class.
So, I'd like to unuse the namespace after including the third party
library header files to avoid the problem.
Any ideas?
Perhaps you are lucky and the offending headers only use using to inject
their own namespace into the global one. Then you could try something like
#define using /##/
#include "OffendingHeader.h"
#undef using
Not really nice, but using using in a header isn't really nice either. I
don't remember what the standard has to say about /##/, but it works with VS
2005:
~~~~~
// BadHeader.h
namespace foo
{
int x;
}
using namespace foo;
~~~~~
// Test.cpp
#define using /##/
#include "BadHeader.h"
#undef using
double x;
~~~~~
Test.cpp compiles with VS 2005, but fails to compile if #define using /##/
is removed.
But may it work or not -- complain to the creator of your library!
HTH
Heinz
.
- Follow-Ups:
- Re: UN-using a namespace?
- From: Alexander Grigoriev
- Re: UN-using a namespace?
- References:
- UN-using a namespace?
- From: Dave Calkins
- UN-using a namespace?
- Prev by Date: Re: ReadFille error caused by USB sniffer
- Next by Date: Thread deadlock misery
- Previous by thread: Re: UN-using a namespace?
- Next by thread: Re: UN-using a namespace?
- Index(es):
Relevant Pages
|