我得到了一些具有以下结构的列表/迭代器的 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();
然后代码以the_iter
这种方式访问 x 和 y:
(*the_iter).x;
(*the_iter).y;
我想将这些更改为更具可读性的版本:
the_iter->x;
the_iter->y;
从我的 C 角度来看,这对于指针解引用完全没问题。迭代器也是这样吗?我的同事有什么理由会使用(*pointer).
而不是p->