教学 & 技术专栏

计算机专业 / liupq (Since 2000)

C++系列文章:17++或是--18,可以这样写吗?(2007-04-25 09:32:00)

不能这样写,后缀++,--要求操作数是一个可以被修改的左值(lvalue)。前缀++,--要求操作数是一个可以被修改的右值(rvalue)。问题中的17,18这样的字面常量值是不行的,编译时会出现错误。
下面是C++ 98标准中的一段话。可认参考

The value obtained by applying a postfix ++ is the value that the operand had before applying the operator.[Note: the value obtained is a copy of the original value ] The operand shall be a modifiable lvalue. The type of the operand shall be an arithmetic type or a pointer to a complete object type. After the result is noted, the value of the object is modified by adding 1 to it, unless the object is of type bool, in which case it is set to true. [Note: this use is deprecated, see annex D. ] The result is an rvalue. The type of the result is the cvunqualified version of the type of the operand. See also 5.7 and 5.17.
The operand of postfix is decremented analogously to the postfix ++ operator, except that the operand shall not be of type bool. [Note: For prefix increment and decrement, see 5.3.2. ]

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BigLeo/article/details/6874655
文章标签: c++ deprecated object c
个人分类: 程序设计理论 CPP
想对作者说点什么? 我来说一句

支票套打程序

2012年09月19日 20.03MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭