avatar
c++ iterator 弱问# Programming - 葵花宝典
a*r
1
#include
using namespace std;
class A {
public:
void begin() const;
private:
map elements;
map::iterator iter;
};
void A::begin() const {
iter = elements.begin();
~~~~~~~~~~~~~~~这里编译的时候报错,显示no match for operator=
这个该怎么fix呢?
}
int main() {
A a;
a.begin();
return 0;
}
avatar
e*a
2
r u trying to change your "iter" in a "const" method?

【在 a*********r 的大作中提到】
: #include
: using namespace std;
: class A {
: public:
: void begin() const;
: private:
: map elements;
: map::iterator iter;
: };
: void A::begin() const {

avatar
a*r
3
thanks, that is a typo, but i still can't assign elements.begin() to
iter in void A::begin(), do u know how to fix that?

【在 e*a 的大作中提到】
: r u trying to change your "iter" in a "const" method?
avatar
t*t
4
how is that a "typo"? show your "corrected" code.

【在 a*********r 的大作中提到】
: thanks, that is a typo, but i still can't assign elements.begin() to
: iter in void A::begin(), do u know how to fix that?

avatar
c*y
5

const function can not change member data in the class

【在 a*********r 的大作中提到】
: #include
: using namespace std;
: class A {
: public:
: void begin() const;
: private:
: map elements;
: map::iterator iter;
: };
: void A::begin() const {

avatar
S*n
6

elements.begin()的类型是 void const;
iter的类型是map< , >::iterator;
你说该怎么改?我不知道。。heihei

【在 a*********r 的大作中提到】
: #include
: using namespace std;
: class A {
: public:
: void begin() const;
: private:
: map elements;
: map::iterator iter;
: };
: void A::begin() const {

avatar
z*e
7
faint, the method is "const", then you cannot change anything.

【在 S*****n 的大作中提到】
:
: elements.begin()的类型是 void const;
: iter的类型是map< , >::iterator;
: 你说该怎么改?我不知道。。heihei

avatar
m*s
8
map is not a mutable iterator, so mutable can't work here.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。