#include <iostream>
using namespace std;
class Test
{
public:
Test(int a = 0,int b = 0)
{
this->a = a;
this->b = b;
}
~Test()
{
cout<<"析构函数"<<endl;
}
Test addTest1(Test &obj)
{
Test tmp(this->a+obj.a,this->b+obj.b);
return tmp;
}
void print()
{
cout<<"a:"<<a<<"b:"<<b<<endl;
}
Test& addTest3(Test &obj)
{
this->a = this->a + obj.a;
this->b = this->b + obj.b;
return *this;
}
protected:
public:
int a;
int b;
};
//全局函数
Test addTest2(Test &a,Test &b)
{
Test tmp(a.a+b.a,a.b+b.b);
return tmp;
}
void display1()
{
Test t1(1,2);
Test t2(3,4);
Test t3;
t3 = addTest2(t1,t2);
t3.print();
}
void display2()
{
Test t1(1,2);
Test t2(3,4);
Test t3 ;
t3 = t1.addTest1(t2);
t3.print();
}
void display3()
{
Test t1(1,2);
Test t2(5,6) ;
t2 = t2.addTest3(t1);
t2.print();
}
int main()
{
display3();
system("pause");
return 0;
}
全局函数pk成员函数
最新推荐文章于 2022-07-03 09:57:43 发布