#include <iostream>
#include<sstream>
using namespace std;
class A{
int value;
public:
A(int a=0):value(a){}
/*A operator+(A b){
value+=b.value;
return (*this);
}
A operator+=(A b){
value+=b.value;
return (*this);
}*/
//重载+=符号,下面是友元函数的用法
friend A operator+=(A &a,A b){
a.value+=b.value;
return a;
}
friend A operator+(A &a,A b){
a.value+=b.value;
return a;
}
//重载+符号
/*A operator++(){
value++;
return value;
}
A operator++(int){
A b(*this);
value++;
return value;
}*/
//重载++符号
friend A operator++(A &a){
a.value++;
return a;
}
friend A operator++(A &a,int){
A temp(a);
a.value++;
return temp;
}
friend ostream& operator<<(ostream &out,A &b){
out<<b.value;
return out;
}
friend istream& operator>>(istream &in,A &b){
in>>b.value;
return in;
}
bool operator >(A a){
if(value>a.value)return true;
else return false;
}
bool operator <(A a){
if(value<a.value)return true;
else return false;
}
operator int(){
return value;
}
};
//以下为main函数 根据需要自己填写使用重载的方法
int main()
{
A a,b;
cin>>a>>b;
int c=a++;
cout<<c;
return 0;
}
面向对象程序设(c++语言)重载函数的几种基本用法
最新推荐文章于 2023-02-12 22:50:03 发布