小编Nul*_*ull的帖子

C++ post-increment:对象与原始类型

我们不能在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编译?

c++ overloading post-increment

6
推荐指数
1
解决办法
166
查看次数

标签 统计

c++ ×1

overloading ×1

post-increment ×1