小编Amj*_*tib的帖子

c2676 - 二进制“++”未定义此运算符

我无法编译下面的代码,但我可以在 Visual Studio 下用另一台笔记本电脑编译它,如果有不同的配置可以设置,我不知道。

#include<iostream>
using namespace std;
class Unary {
private:
    int x, y;

public:
    Unary(int i = 0, int j = 0) {
        x = i;
        y = j;
    }
    void show()
    {
        cout << x << " " << y << endl;
    }
    void operator++()
    {
        x++;
        y++;
    }
};

int main() {
    Unary v(10, 20);
    v++;
    v.show();
}
Run Code Online (Sandbox Code Playgroud)

它给出了以下错误:

Error C2676: binary '++': 'Unary' does not define this operator or a conversion to a type acceptable …
Run Code Online (Sandbox Code Playgroud)

c++ oop visual-studio-2015

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

标签 统计

c++ ×1

oop ×1

visual-studio-2015 ×1