我得到了一些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->