#include<iostream>
using namespace std;
class test
{
int x;
int y;
public:
test(int a);//一个参数的构造函数
test(int a,int b);//两个参数的构造函数
void disp();
};
test::test(int a):x(a)
{
}
test::test(int a,int b):x(a),y(b)
{
}
void test::disp()
{
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
test f()//全局函数,函数的返回值为对象,切忌和成员函数混淆
{
test dt(100,200);
return dt;
}
int main()
{
test p(10,20);
p.disp();
p=f();
p.disp();
}
/*result:
x=10
y=20
x=100
y=200
*/
因篇幅问题不能全部显示,请点此查看更多更全内容