c++运算符重载
作者:互联网
c++运算符重载
#include <iostream>
#include "point.h"
#include "circle.h"
using namespace std;
class myint {
friend ostream & operator<<(ostream &cout,myint p);///友元-全局函数
private:
int num;
public:
myint() {
num = 0;
}
myint& operator++(){///返回引用
this->num++;
return *this;
}
myint operator++(int){///int 代表占位参数,可以用于区分前置和后置的区别;
myint temp=*this;
this->num++;
return temp;
}
};
ostream & operator<<(ostream &cout,myint p){
cout<<p.num;
return cout;
}
int main() {
int i = 0;
cout << i++<<endl;
cout<< (++i)<<endl;
myint j;
cout<<j++<<endl;
cout<<(++j)<<endl;
return 0;
}
标签:++,c++,运算符,operator,int,num,myint,重载,include 来源: https://blog.csdn.net/weixin_45436102/article/details/114856784