C++系列文章:17++或是--18,可以这样写吗?(2007-04-25 09:32:00)
来源:互联网 发布:如何戒淘宝成瘾 编辑:程序博客网 时间:2024/05/22 08:16
不能这样写,后缀++,--要求操作数是一个可以被修改的左值(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. ]
- C++系列文章:17++或是--18,可以这样写吗?(2007-04-25 09:32:00)
- C#中验证文章的正则表达式可以这样写
- 面试问题:线程可以这样写吗?
- UPDATE可以这样写!
- 写代码文章最好这样
- 原来程序可以这样写
- ASP还可以这样写!
- 原来update可以这样写!
- Public 原来可以这样写
- mysql语句可以这样写
- 写文章可以得积分吗?
- 你可以这样去写,但是它会让C变成Algol
- 【C语言】1到100求和,原来还可以这样写?
- 这样可以吗?
- 这样拆墙就可以吗?
- Delphi类也可以这样写
- 原来Javascript还是可以这样写的
- 原来Javascript还是可以这样写的
- C++:一段代码(2007-05-08 21:32:36)
- Unix/Linux常用命令
- C++系列文章:读入一个整数时输入一个浮点数会有什么后果?(2007-04-25 09:33:53)
- easyUI属性汇总
- 计划,,,执行
- C++系列文章:17++或是--18,可以这样写吗?(2007-04-25 09:32:00)
- java 双向查找的集合
- 经典语录
- C++系列文章 main函数(2007-04-24 15:33:04)
- Android权限列表permission说明
- v4l2 spec 中文 Ch03
- 在VC2005(Express版)中如何创建标准C++程序
- Hibernate断网后不能解析cfg配置文件,连接失败的问题
- 头文件之惑 C++系列(2)(2006-11-21 10:16:17)