C ++运算符优先级 [英] C++ operator precedence
问题描述
假设我们有一个指向分配给堆空间的内存的指针列表上的迭代器(iter)
Lets say we have an iterator (iter) over a list of pointers to memory assigned to heap space, if I do that
delete (*iter++)
我对,优先权是先解除引用迭代器以获取内存地址,然后释放空间,然后递增迭代器以释放下一个元素?
am I right that the precedence is first dereference iterator to get memory address then free the space and then increment the iterator to free the next element ?
推荐答案
效果与您所写的相同,但是可以通过稍有不同的顺序来实现:
The effect is as you write, but it's achieved using a slightly different sequence:
-
后递增优先级最高,因此首先对其进行评估.但是,它的返回值(由进一步的运算符处理)是
iter
在递增之前的值.
接下来将评估解除引用,返回iter
的非增量值指向"的指针.
Dereference is evaluated next, returning pointer to which the non-incremented value of iter
was "pointing."
delete
最后被求值,并且指针被删除.
delete
is evaluated last, and the pointer is deleted.
这篇关于C ++运算符优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!