// Class.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Point
{
public:
Point(float x=0,float y=0);
void setPoint(float,float);
float getX(){return x;}
float getY(){return y;}
friend ostream & operater << (ostream &,const Point &);
protected:
float x,y;
};
Point::Point(float a, float b)
{
x=a;y=b;
}
void Point::setPoint(float a,float b)
{
x=a;y=b;
}
ostream &operater<<(ostream & output,Point &p)
{
output<<"["<<p.x<<","<<p.y<<"]";
return output;
}
int main()
{
Point p(4.3,5.2);
cout<<"x="<<p.getX()<<"y="<<p.getY()<<endl;
p.setPoint(5.6,7.6);
cout<<"p(new)"<<p<<endl;
return 0;
}
|