#include<iostream>
using namespace std;
class A
{
int data;
public:
A(int d=0):data(d){}
void show()
{
cout<<"data="<<data<<endl;
}
A operator-(const A& o)//A sub(const A& o)
{
int dif=data-o.data;
return A(dif);
}
};
int main()
{
A obj1(40),obj2(50);
A obj3,obj4;
obj3=obj1.operator-(obj2);//obj3=obj1.sub(obj2);
obj3.show();
obj4=obj1-obj2;
obj4.show();
}
【c++程序】operator运算符函数
最新推荐文章于 2024-06-21 14:20:12 发布