小编Hos*_*ack的帖子

迭代器取消引用然后"." 算子与." - >"操作员

我得到了一些C++代码,它具有以下结构的列表/迭代器.

typedef struct{
  int x;
  int y;
}my_struct;

std::list<my_struct> the_list;
std::list<my_struct>::iterator the_iter = the_list.begin();
Run Code Online (Sandbox Code Playgroud)

然后代码以the_iter这种方式访问x和y :

(*the_iter).x;
(*the_iter).y;
Run Code Online (Sandbox Code Playgroud)

我想将这些更改为更易读的版本:

the_iter->x;
the_iter->y;
Run Code Online (Sandbox Code Playgroud)

从我的C角度来看,这对于指针解除引用来说完全没问题.迭代器也是如此吗?有没有理由说我的同事会用(*pointer).而不是p->

c++ listiterator

2
推荐指数
2
解决办法
656
查看次数

标签 统计

c++ ×1

listiterator ×1