移动点的坐标
#include "stdafx.h"
#include "iostream"
using namespace std;
class Point
{
public:
Point(double x,double y);
~Point();
//获得类的成员变量_x的值
double GetX()const{ return _x; }
//获得类的成员变量_y的值
double GetY()const { return _y; }
//点的坐标(_x,_y)移动
void Move(double xOff, double yOff)
{
_x += xOff, _y += yOff;
}
private:
double _x, _y;
};
Point::Point(double x, double y):_x(x), _y(y)
{
}
Point::~Point()
{
}
int _tmain()
{
Point pt(1.5, 2.5);
pt.Move(2.5, 1.5);
//“Point::GetX”: 函数调用缺少参数列表;请使用“&Point::GetX”创建指向成员的指针
cout << '(' << pt.GetX() << ',' << pt.GetY() << endl;
return 0;
}