由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ iterator 弱问
相关主题
问一个C++ set和unordered_set iterator的问题这段C++代码有啥问题
const in c++C++如何快速输入iterator类型名
请教c++的string vector问题,谢谢! (转载)一个C++的概念问题
please help debug this codeWhy should i include .cpp instead of .h
return Triangular_iterator( _beg_pos );意思template question
a c++ question[C++] 新手报错求助
c++ private 问题stl iterator in gdb
基本功不扎实,问个问题function declaration
相关话题的讨论汇总
话题: iter话题: iterator话题: const话题: map话题: void
进入Programming版参与讨论
1 (共1页)
a*********r
发帖数: 7
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;
}
e*a
发帖数: 32
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 {

a*********r
发帖数: 7
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?
t****t
发帖数: 6806
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?

c****y
发帖数: 24
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 {

S*****n
发帖数: 227
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 {

z***e
发帖数: 5393
7
faint, the method is "const", then you cannot change anything.

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

m******s
发帖数: 612
8
map is not a mutable iterator, so mutable can't work here.
1 (共1页)
进入Programming版参与讨论
相关主题
function declarationreturn Triangular_iterator( _beg_pos );意思
Why C++11 introduce "decltype" and "auto"?a c++ question
C++ class cross reference problemc++ private 问题
[合集] iterator & const_iterator基本功不扎实,问个问题
问一个C++ set和unordered_set iterator的问题这段C++代码有啥问题
const in c++C++如何快速输入iterator类型名
请教c++的string vector问题,谢谢! (转载)一个C++的概念问题
please help debug this codeWhy should i include .cpp instead of .h
相关话题的讨论汇总
话题: iter话题: iterator话题: const话题: map话题: void