无法分配矢量迭代器

时间:2015-05-04 15:38:08

标签: c++ vector stl iterator

我不能在下面的代码中使用=运算符,因为我得到compiller错误。我无法理解什么是错的。

<Tkinter.Event instance at 0x028C5558>

我收到以下错误:

var='asdf'

我会帮助你!

1 个答案:

答案 0 :(得分:5)

xvconst引用,意味着只能在其中调用const个成员函数。 const的{​​{1}}重载返回std::vector<double>::begin(),并且不能用于构造const_iterator,因为它会破坏const-coreectness。

所以你需要

iterator

请注意,从C ++ 11开始,您还有其他选择:

std::vector<double>::const_iterator it;

或者,如果要迭代所有元素,基于范围的循环可能会更好:

for (auto it = xv.begin(); it < xv.end(); it++)