for循环中的向量迭代器

vector iterator in for loop

我有这个循环

   for(vector<Graph*>::iterator itr = current->getchildren().begin(); itr = current->getchildren().end(); ++itr)

当前是:

   Graph* current = new Graph(*root);

    class Graph
    {
    private:

        vector<Graph*>              children;

我在循环中遇到这个错误:

error: could not convert '(itr = (* &(& current->Graph::getchildren())->std::vector<_Tp, _Alloc>::end >()))' from 'std::vector::iterator {aka __gnu_cxx::__normal_iterator >}' to 'bool'

我不知道这里出了什么问题。我一直在以前版本的代码中使用这个循环没有问题(只是改变了当前的名称)

有什么想法吗?

谢谢

尝试将迭代器与末尾进行比较 !=

for (...; itr != current->getchildren().end(); ...)

在您的代码中,您使用赋值运算符 = 将迭代器的值立即设置为末尾。这个表达式有一个迭代器的类型,幸运的是,编译器没有找到将它转换为 bool 的方法