#ifndef _POINT_H
#define _PIONT_H
class Point {//类的定义
public://外部接口
Piont();
Piont(int x, int y);
~Piont();
void move(int newX, int newY);
int getX() const { return x; }
int getY() const { return y; }
static void showCount();//静态数据成员
private:
int x, y;
#endif //_PIONT_H
};
#include <iostream>
#include "Piont.h"
using namespace std;
Point::Point() {
x = y = 0;
cout << "Default Constructor called." << endl;
}
Point::Point(int x, int y) :x(x),y(y) {
cout << "Constructor called." << endl;
}
Point::~Point() {
cout<<"Destructor called." << endl;
}
void Point::move(int newX, int newY) {
cout << "Moving the point to(" << newX << "," << newY << ")" << endl;
x = newX;
y = newY;
}
// 6-3对象数组应用举例.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "Piont.h"
using namespace std;
int main()
{
cout << "Entering main..." << endl;
Point a[2];
for (int i = 0; i < 2; i++)
a[i].move(i + 20, i + 20);
cout<<"Exiting msin..." << endl;
return 0;
}