您的位置:首页 > 其它

4-3-2

2013-11-02 15:04 316 查看
#include <iostream>
using namespace  std;
class Point
{
public:
Point(int xx=0,int yy=0)
{
x=xx;
y=yy;
cout<<"Constructor is called"<<endl;
}
Point(Point &p);
int getX()
{
return x;
}
int getY()
{
return y;
}
private://number(编号)、sex(性别)、birthday(出生日期)、id(身份证号)
int x,y;
};
Point::Point(Point &p)
{
x=p.x;
y=p.y;
cout<<"Calling the copy constructor"<<endl;
}

void f(Point p)
{
cout<<p.getX()<<endl;
}

Point g()
{
Point a(1,2);
return a;
}
int main()
{
cout<<"Point a(1,2);"<<endl;
Point a(1,2);
cout<<"Point b(a);"<<endl;
Point b(a);
cout<<"Point c=a;"<<endl;
Point c=a;
cout<<"f(a);"<<endl;
f(a);
cout<<"c=g();"<<endl;
c=g();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: