关于友元重载的问题很简单的但老是编译有错!!
//Point类的定义#ifndef POINT_H
#define POINT_H
#include<iostream.h>
class Point{
public:
Point(int a=0,int b=0);
Point(Point&);
~Point();
int get_x()const;
int get_y()const;
void put_x(int a);
void put_y(int b);
Point operator=(const Point& p1);
Point operator+(const Point& p1);
Point operator*(int i);
private:
int x,y;
friend istream& operator>>(istream& in,Point& p1);
//重载提取操作符函数(输入),友元函数
friend ostream& operator<<(ostream& out,Point& p1);
//重载插入操作符函数(输出),友元函数
};
#endif
//此处是成员函数的实现。
ostream& operator <<(ostream& out,Point& p1)
{ out <<"输入2个数"<<"("<<p1.x<<p1.y<<")"<<endl;
return out;
}
istream& operator>> (istream& in,Point& p1)
{
in>>p1.x>>p1.y;
return in
}
//测试成员函数
#include"point.h"
void main()
{
Point p2(1,2),p1;
cout<<p2<<p1;
}
[ 本帖最后由 lzywin 于 2009-12-1 21:42 编辑 ]