//单目运算符重载为成员函数 后++ 采用了哑元
#include<iostream>
using namespace std;
class CPoint {
private:
int x,y;
public:
CPoint(int a = 0,int b = 0){
x = a;
y = b;
}
CPoint operator++(int);
void display();
};
CPoint CPoint::operator++(int){
x++;
y++;
return *this;
}
void CPoint::display(){
cout << x << " " << y << endl;
}
int main(void){
CPoint p;
p++;
p.display();
return 0;
}
//单目运算符重载为成员函数 前++
#include <iostream>
using namespace std;
class CPoint {
private:
int x,y;
public:
CPoint(int a = 0,int b = 0){
x = a;
y = b;
}
CPoint operator++();
void display();
};
CPoint CPoint::operator++(){
x++;
y++;
return *this;
}
void CPoint::display(){
cout << x << " " << y << endl;
}
int main(void){
CPoint p;
++p;
p.display();
return 0;
}
单目运算符重载为成员函数 前++ 和后++的使用
最新推荐文章于 2022-04-08 16:48:05 发布