#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 << "Objectcount=" << count << endl;
}
private:
int x,y;
static int count;
};
int Point::count = 0;
int main() {
Point a(1, 2);
cout << "PointA: " << a.getX() << ", " << a.getY();
a.showCount();
Point b(a);
cout << "PointB: " << b.getX() << ", " << b.getY();
b.showCount();
return 0;
}
结果: