问题标签 [const-iterator]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - std::map::begin() 返回带有垃圾的迭代器
在创建 const_iterator termWeight 时出现问题:
正如您在上图中所见, termWeight const_iterator 包含无效数据。但是,const std::map 文档是完全有效的 std::map。我想不出为什么会发生这种情况。
我最近了解到 std::map::cbegin() 存在。我应该改用那种方法吗?
编辑:包括更多上下文
c++ - 迭代器 - 在 C++11 中没有匹配的擦除函数
我无法解释这种行为:
其中 File 是我自己的类(不包括标准), this->files 是 Files 的向量
当我编译我得到的代码时(见第 2 行)
甚至文档 都说没关系,但是错误no matching function for call to std::vector::erase(std::vector::const_iterator&)真的很奇怪。
我真的需要能够通过迭代器删除矢量项。有人可以帮我吗?提前谢谢。
c++ - 如何从 list::const_iterator 获取 list::iterator
如果我有一个对 stl::list 的(非常量)引用和一个指向该列表中特定位置的 const_iterator,我怎样才能获得一个指向同一个地方的迭代器?(我想擦除该位置的元素,但列表没有 const_iterators 的擦除方法)
这似乎不应该违反 const 正确性,因为它仅在我对列表有非常量引用时才有效。
编辑:
等一下,看看 CPP 参考:http ://www.cplusplus.com/reference/list/list/erase/它说你可以用 const_iterator 调用 erase()。那么为什么我的编译器会抱怨呢?我正在使用 gcc 4.6 --std=c++0x
错误是:
c++ - 链表常量迭代器
我已经实现了一个双向链表,并创建了一个可扩展的迭代器std::iterator
。我现在正在尝试创建一个const
版本。
我试过了:
如果我这样做,我会收到此错误:
这是我的operator--
:
如果我把
...我无法修改_current
我如何使我的迭代器现在像 a 一样工作,const_iterator
以便从我的链表中我可以调用获取 and 的 const 版本begin()
,end()
以及cbegin()
and cend()
?
c++ - 遍历 C++ 容器 - 最快的方法是什么?
请回答以下问题:
1)如果我在循环中所做的事情改变了 my_vector 元素的值,那么使用 B 而不是 A 更有效吗?这里效率=更快的遍历。如果是,为什么?
2)如果不修改my_vector的元素,三者中最快的方法是什么?
c++ - c++: const_iterator 和 for-each 循环
我正在用 C++ 制作自己的 Vector 实现。这是一个两部分的问题。
第 1 部分:尝试遍历 Vector 时,我的 begin() 和 end() 迭代器无法处理输入参数。下面是我的整个 Vector.h 实现:
这些是向量中的 beign() 和 end() 函数:
并且......最后(对不起长度)......这是触发编译错误的测试代码:
我收到的错误是:
我一直在研究这个问题几个小时,但找不到解决方案。有小费吗?
第 2 部分:除了我上面所做的之外,还有另一种实现 const_iterator 的方法吗?对我来说,将这么多的函数从迭代器重新定义为 const_iterator 似乎是多余的。我什至需要创建一个 const_iterator 类吗?
c++ - const_iterator、find_if 和 bind2nd:错误调用不匹配
我尝试使用 find_if 通过其值在地图中查找键。但我无法编译代码:
Bill::CodeCurrency
是一个枚举。
错误:
你能帮我确定这里的错误是什么吗?
c++ - Why can't I call a template base class constructor with a const_iterator?
For some reason, the following code gives the error Symbol 'TemplateBase' could not be resolved.
:
Strangely, no error appears when I remove the ::const_iterator
and only std::map<std::string, int>
remains:
Additionally, the following function gives no error either, so it really seems related to the combination of a template base class call with a const_iterator:
Is there some rule against using const_iterator as an argument for base class template constructors that I'm unaware of? Or is this a compiler bug?
I'm compiling with MinGW 64bit 4.9.0 on Windows 7, using C++11.
c++ - STL const_iterator cast -- compiler differences
I'm porting a big chunk of code from gcc to Visual Studio 2013. The following code sample works fine (!) on gcc 4.4, but compiling begin()
and end()
fails on VS2013 with:
error C2440: '' : cannot convert from 'unsigned char *' to 'std::_Vector_const_iterator>>'
Given that I don't want to rewrite the whole thing, is there a portable way to create these const_iterators?
c++ - C++ 向量 const_iterator 错误
我有以下 C++ 代码:
但是,我在编译时收到以下错误:
我一直在思考它很长一段时间,但无法弄清楚为什么我会收到这个错误。我还尝试过 clang 看看我是否可以从它的错误声明中做出任何事情,但不能。将不胜感激。谢谢