[英]Iterator Dereferencing
I am using a vector in c++, 我在c ++中使用向量,
vector<Agents> agentlist;
Why does this work, 为什么这样做,
(agentlist.begin() )->print();
and this not? 这不是吗?
*(agentlist.begin() ).print();
Isn't it valid to dereference an iterator using *
? 使用
*
取消引用迭代器是否有效?
See operator Precedence , .
见运算符Precedence ,
.
has higher precedence than *
优先级高于
*
*(agentlist.begin()).print();
represents as: 表示为:
*((agentlist.begin()).print());
While iterator has no .print()
function call, compiler will throw out compile error. 虽然迭代器没有
.print()
函数调用,但编译器会抛出编译错误。
You need: 你需要:
agentlist.begin()->print(); or (*agentlist.begin()).print();
Try using (*(agentlist.begin())).print();
尝试使用
(*(agentlist.begin())).print();
:) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.