【发布时间】:2011-01-08 23:37:19
【问题描述】:
这似乎是一个愚蠢的问题,但为什么在许多语言中存在++ 和-- 运算符的前缀和后缀版本,但没有类似@987654323 等其他运算符的前缀/后缀版本@ 或 -=?例如,如果我可以编写这段代码:
myArray[x++] = 137; // Write 137 to array index at x, then increment x
我应该能写出类似的东西
myArray[5 =+ x] = 137; // Write 137 to array index at x, then add five to x
当然,这样的运营商是不存在的。是否有一个原因?在 C/C++/Java 中,这似乎是一种奇怪的不对称。
【问题讨论】:
-
所以,基本上,你问为什么只允许±1的特殊情况?
-
就个人而言,我赞成
myArray[x++++++++++++++++++++] = 137;语法。 -
@pst 或者
myArray[x.plusPlus(10)] = 137;怎么样 -
@templatetypedef :我认为,这看起来更好>>
myArray[x=+5] = 137;(添加后)......和现有的>>myArray[x+=5] = 137;(预添加)......这个想法是,保持x始终在左侧! -
应该将
x=-1解析为x =- 1还是x = -1? :)