使用命名空间问题
当我使用以下内容时,
#include <map>
using namespace LCDControl;
对 std 命名空间的任何引用最终都会与 LCDControl 命名空间相关联。
例如:
Generic.h:249: error: 'map' is not a member of 'LCDControl::std'
我该如何解决这个问题?我在查看的任何文档中都没有看到任何与此相关的内容。大多数人都说不要使用:using namespace std;。
这是第 249 行:
for(std::map<std::string,Widget *>::iterator w = widgets_.begin();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来
std
lcdcontrol
中隐藏了全局std
namespace。尝试使用:: STD :: MAP
而不是std :: Map
。我要说的是,要么使用
使用namespace std
在lcdcontrol
命名空间中的某个地方,或者可能有一个#include
的定义来定义 代码> std 在lcdcontrol
名称空间中。例如:
它将在
&lt; map&gt;
中定义所有符号,作为lcdcontrol :: std
的一部分,这又将隐藏全局std
,或者至少在内部名称空间中定义的任何符号,我不确定。当我在VS2008下尝试此操作时,我遇到了一个错误:
It looks like there's a
std
namespace withinLCDControl
that's hiding the globalstd
namespace. Try using::std::map
instead ofstd::map
.I would say that either there's a
using namespace std
somewhere within theLCDControl
namespace, or possibly there's an#include
of a STL header that definesstd
within theLCDControl
namespace.e.g.:
Which would define all the symbols in
<map>
as part ofLCDControl::std
, which in turn would hide the globalstd
, or at least any symbols defined in the inner namespace, I'm not sure.When I tried this under VS2008, I got an error:
“map”类位于 std 命名空间中,因此您必须在某个地方对其进行限定。您如何限定您的地图对象?这样做应该没有问题:
如果您不想每次都显式限定它,但也不想污染您的全局名称空间,您也可以这样做:
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:
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: