首页 > 其他 > 详细

自考新教材-p148_5(2)

时间:2020-02-07 02:02:38      阅读:113      评论:0      收藏:0      [点我收藏+]

源程序:

#include <iostream>

using namespace std;
class Point {
public:
Point(int x = 0, int y = 0) :x(x), y(y)
{
count++;
}
Point(Point&p) {
x = p.x;
y = p.y;
count++;
}
~Point()
{
count--;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
void showCount()
{
cout << "Object count=" << count << endl;
}
private:
int x, y;
static int count;
};
int Point::count = 0;
int main()
{
Point a(4, 5);
cout << "Point A:" << a.getX() << "," << a.getY() << endl;
a.showCount();
Point b(a);
cout << "Point B:" << b.getX() << "," << b.getY() << endl;
b.showCount();
system("pause");
return 1;
}

运行结果:

技术分享图片

 

自考新教材-p148_5(2)

原文:https://www.cnblogs.com/duanqibo/p/12270891.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!