您的位置:首页 > 其它

第六周上机实践项目:复制构造函数

2016-04-07 09:06 477 查看
/*
*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:aaa.cpp
*作    者:赵子琳
*完成日期:2016年4月7日
*版 本 号:v1.0
*
*问题描述:复制构造调用函数的三种情况。
*/
#include<iostream>
using namespace std;
class Point//Point类的定义
{
public:
Point(int xx=0,int yy=0)//构造函数
{
x=xx;
y=yy;
}
Point(Point &p);//复制构造函数
int getX()
{
return x;
}
int getY()
{
return y;
}
private:
int x,y;
};
Point::Point(Point &p)
{
x=p.x;
y=p.y;
cout<<"Calling the copy constructor"<<endl;
}
void fun1(Point &p)
{
cout<<p.getX()<<endl;
}
Point fun2()
{
Point a(1,2);
return a;
}
int main()
{
Point a(4,5);
Point b=a;
cout<<b.getX()<<endl;
fun1(b);
b=fun2();
cout<<b.getX()<<endl;
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: