现在的位置: 首页 > 综合 > 正文

为什么a++不可以做左值,而++a可以

2013年01月28日 ⁄ 综合 ⁄ 共 185字 ⁄ 字号 评论关闭

1.
a++返回的是一个临时变量,用于保存a在自增之前的值。
2.
++a省去一个临时变量,返回的是a


如果懂c++的重载,那么
struct Object
{int i;
Object operator++(int)//后缀++
{
Object t=*this;
i++;
return t;
}
Object& operator++()//前缀++
{
i++;
return *this;
}
};

抱歉!评论已关闭.