在我的头文件中,我包含了std :: map并使用了适当的名称空间。
我的一个成员是:使用映射迭代器编译错误
map<unsigned int, double> pT_Spam;
在我.cpp文件我试图做一些事情,我一直在做频繁的一段时间:
for(map<unsigned int, double>::iterator it=pT_Spam.begin() ; it!=pT_Spam.end() ; it++) {/*code*/}
以上,即使是中提到的一个在cplusplus.com上使用std :: map的例子。尽管我已经做了相当多的代码的其他部分造成任何编译错误一样,在这一行,我从Cygwin的出现以下错误:
error: conversion from `std::_Rb_tree_const_iterator<std::pair<const unsigned int, double> >' to non-scalar type `std::_Rb_tree_iterator<std::pair<const unsigned int, double> >' requested
这似乎很奇怪。任何想法可能是错误的? (我的头,当然,包括在我的.cpp)
这是抱怨,由begin()返回的迭代器是一个const_iterator,但你将它分配给一个迭代器。但我不知道为什么,这对我来说也是正确的。这是什么编译器? – Joe 2012-01-06 01:53:09
[begin()](http://cplusplus.com/reference/stl/map/begin/)似乎也能够返回非常量迭代器。 我在Windows上使用Cygwin的g ++。 – jathanasiou 2012-01-06 01:58:00