【发布时间】:2013-07-03 06:56:53
【问题描述】:
我有一个 std::map,我想从第二个条目开始对其进行迭代。
我可以很好地解决这个问题,但我对为什么“显而易见”的语法无法编译感到困惑。错误消息没有帮助,因为它引用了std::string,我在这里没有使用。
这里有一些代码
// Suppose I have some map ...
std::map<int, int> pSomeMap;
// This is fine ...
std::map<int, int>::const_iterator pIterOne = pSomeMap.begin();
++pIterOne;
// This doesn't compile ...
std::map<int, int>::const_iterator pIterTwo = pSomeMap.begin() + 1;
Visual Studio 2012 在上述行出现以下错误:
error C2784: 'std::_String_iterator<_Mystr> std::operator +
(_String_iterator<_Mystr>::difference_type,std::_String_iterator<_Mystr>)' :
could not deduce template argument for 'std::_String_iterator<_Mystr>' from 'int'
这里发生了什么?
【问题讨论】:
-
有史以来最奇怪的错误信息?
-
@NathanOliver:如果您正在编辑帖子以将错误消息从引号移动到代码块,我可以建议添加
<!-- language: lang-none -->以禁用语法突出显示吗?
标签: c++ visual-c++ visual-studio-2012 stl