| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 675 人关注过本帖
标题:关于友元重载的问题很简单的但老是编译有错!!
取消只看楼主 加入收藏
lzywin
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2009-11-11
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
关于友元重载的问题很简单的但老是编译有错!!
//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 编辑 ]
搜索更多相关主题的帖子: 重载 编译 
2009-12-01 20:58
lzywin
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2009-11-11
收藏
得分:0 
哪里错了?
这个类的定义是给好的 只要求写成员函数的实现跟主函数
2009-12-01 21:37
lzywin
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2009-11-11
收藏
得分:0 
那个分号加上还是编译有误啊
2009-12-01 22:37
快速回复:关于友元重载的问题很简单的但老是编译有错!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011009 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved