C ++运算符优先级 [英] C++ operator precedence

查看:98
本文介绍了C ++运算符优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个指向分配给堆空间的内存的指针列表上的迭代器(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:

  1. 后递增优先级最高,因此首先对其进行评估.但是,它的返回值(由进一步的运算符处理)是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆