我无法编译下面的代码,但我可以在 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)