我们不能在rvalues上使用预增量:
int i = 0;
int j = ++i++; // Compile error: lvalue required
Run Code Online (Sandbox Code Playgroud)
如果我们定义一个类:
class A
{
public:
A & operator++()
{
return *this;
}
A operator++(int)
{
A temp(*this);
return temp;
}
};
Run Code Online (Sandbox Code Playgroud)
然后我们可以编译:
A i;
A j = ++i++;
Run Code Online (Sandbox Code Playgroud)
A对象和int数据类型之间有什么不同
j = ++i++;
Run Code Online (Sandbox Code Playgroud)
用A编译但不用int编译?