<分区>
我正在使用 Visual Studio 2013 编译非常简单的代码:
std::set<int> a{ 1, 2, 3 };
std::remove(a.begin(), a.end(), 3);
我希望这不会出错,但我很惊讶。错误发出:
Error 1 error C3892: '_Next' : you cannot assign to a variable that is const c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm
怎么会这样? a 是非常量 std::set。 std::remove() 移动它的元素并且看起来完全合法。
在 VS 2008 中,下面类似的代码编译没有错误:
std::set<int> a;
std::remove(a.begin(), a.end(), 3);