views:

114

answers:

2

When I use the following

#include <map>

using namespace LCDControl;

Any reference to the std namespace ends up being associated with the LCDControl name space.

For instance:

Generic.h:249: error: 'map' is not a member of 'LCDControl::std'

How do I get around this? I didn't see anything specific to this on any documentation I looked over. Most of them said not to use: using namespace std;.

Here's line 249:

for(std::map<std::string,Widget *>::iterator w = widgets_.begin();
+1  A: 

The 'map' class lives in the std namespace, so you are going to have to qualify that somewhere. How are you qualifying your map object? You should have no problem doing this:

std::map<foo> myMap;

You can also do something like this if you do not want to explicitly qualify it every time, but also do not want to pollute your global namespace:

using std::map;
Ed Swangren
I'm qualifying it with std::map.
Scott
Yeah, I see that now. Looks like your LCDControl namespace is polluting *your* global namespace.
Ed Swangren
+4  A: 

It looks like there's a std namespace within LCDControl that's hiding the global std namespace. Try using ::std::map instead of std::map.

I would say that either there's a using namespace std somewhere within the LCDControl namespace, or possibly there's an #include of a STL header that defines std within the LCDControl namespace.

e.g.:

namespace LCDControl
{
    #include <map>
}

Which would define all the symbols in <map> as part of LCDControl::std, which in turn would hide the global std, or at least any symbols defined in the inner namespace, I'm not sure.

When I tried this under VS2008, I got an error:

namespace testns
{
    int x = 1;
}

namespace hider
{
    namespace testns
    {
        int x = 2;
    }
}

int y = testns::x;
using namespace hider;
int z = testns::x;    // <= error C2872: 'testns' : ambiguous symbol
Tim Sylvester
Yeah, I think that's what happened. Here I go 'a searching.
Scott
Yeah that's what it was. Curious that this didn't fix my initial issue. lol... CHAR is still defined multiple times according to the linker. Oh well, at least everything's inside a namespace now.
Scott
Glad to hear it.
Tim Sylvester