0

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();
23
  • What compiler? Also, do you have anything named map in your LCDControl namespace? Why use using namespace anyway? :) Commented Oct 20, 2009 at 1:03
  • GMan, no 'map is in the LCDControl namespace. I used a namespace because I kept running into names associated with outside header files. For instance, in this case I had something named CHAR, and it conflicted with something somewhere. Instead of renaming it, I dealt with it by wrapping everything inside a namespace. Of course I've never used C++ namespaces before, so here I am. :) Commented Oct 20, 2009 at 1:05
  • 1
    That's strange, it's behaving as if you forgot to include <map>. Does it work if you use ::std::map instead of std::map? Commented Oct 20, 2009 at 1:09
  • 1
    Hmm, seems as if something in LCDControl is hiding std. Is there a using namespace std within the namespace LCDControl { } anywhere? Commented Oct 20, 2009 at 1:13
  • 1
    One thing that might cause that is if one of the STL headers is being included somewhere within the LCDControl namespace. e.g., namespace LCDControl { #include <string> }. Commented Oct 20, 2009 at 1:15

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, I think that's what happened. Here I go 'a searching.
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.
1

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;

2 Comments

I'm qualifying it with std::map.
Yeah, I see that now. Looks like your LCDControl namespace is polluting your global namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.