问题及代码 :
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称 :
*作 者 : 刘云
*完成日期 : 2016年3月12号
*版 本 号 : v1.0
*
*问题描述 : c++例4-2
*输入描述 : point类的完整程序
*程序输出 :
*/
#include<iostream>
using namespace std;
class 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 constructer"<<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;
}
第4周项目6 point类的完整程序
最新推荐文章于 2021-03-31 21:29:34 发布