#pragma once
#include <iostream>
using namespace std;
class Point
{
public:
Point(); //构造函数
Point(float x, float y);//构造函数
void SetPoint(float x, float y);
Point GetPoint();
float GetX();
float GetY();
~Point();
private:
float x, y;
};
#include "stdafx.h"
#include "Point.h"
Point::Point()
{
}
Point::Point(float x, float y)//构造函数
{
this->x = x;
this->y = y;
}
void Point::SetPoint(float x, float y)
{
this->x = x;
this->y = y;
}
Point Point::GetPoint()
{
Point Rpoint; //返回的点
Rpoint.x = this->x;
Rpoint.y = this->y;
return Rpoint;
}
float Point::GetX()
{
return this->x;
}
float Point::GetY()
{
return this->y;
}
Point::~Point()
{
}
// thisPointer_example.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "Point.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Point p(2.2f, 3.3f); //此时构造函数中的this指针指向对象p
cout << "点坐标是:" << p.GetPoint().GetX() << ", " << p.GetPoint().GetY() << endl;
cout << "点坐标是:" << p.GetX() << ", " << p.GetY() << endl;
p.SetPoint(3.5f, 4.2f);
cout << "点坐标是:" << p.GetX() << ", " << p.GetY() << endl;
getchar();
return 0;
}
运行结果: