| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 744 人关注过本帖
标题:帮帮忙,重载运算符相关的
取消只看楼主 加入收藏
hy247767221
Rank: 2
来 自:襄樊
等 级:论坛游民
帖 子:41
专家分:22
注 册:2011-7-27
结帖率:87.5%
收藏
已结贴  问题点数:0 回复次数:3 
帮帮忙,重载运算符相关的
#include<iostream>
using namespace std;

class Point
{
    public:
        Point() : x(0), y(0)
        {
            cout << "Initialize!" << endl;
        }
        Point(int a, int b) : x(a), y(b)
        {
            cout << "Initialize!" << endl;
        }
        friend ostream &operator << (ostream& output, Point& point);
        friend istream &operator > (istream& input, Point &point);
        ~Point()
        {
            cout << "Set free!" << endl;
        }
    private:
        int x, y;
};

ostream &operator << (ostream& output, Point& point)
{
    output << "(" << point.x << "," << point.y << ")" << endl;
    return output;
}
istream &operator>> (istream& input, Point &point)
{
    input >> point.x;
    input >> point.y;
    return input;
}


int main()
{
    Point A(3, 5), B;
    cin >> B;
    cout << A << endl << B << endl;

    return 0;
}
搜索更多相关主题的帖子: include public friend point class 
2011-10-14 15:30
hy247767221
Rank: 2
来 自:襄樊
等 级:论坛游民
帖 子:41
专家分:22
注 册:2011-7-27
收藏
得分:0 
回复 2楼 nomify
好像不对啊 ,不是这样的,我用的是VC++编译的
2011-10-14 17:04
hy247767221
Rank: 2
来 自:襄樊
等 级:论坛游民
帖 子:41
专家分:22
注 册:2011-7-27
收藏
得分:0 
回复 5楼 yy7software
为什么要这样呢,不是友员函数么,放在外面为什么不行呢?
2011-10-14 19:52
hy247767221
Rank: 2
来 自:襄樊
等 级:论坛游民
帖 子:41
专家分:22
注 册:2011-7-27
收藏
得分:0 
回复 7楼 niitzz
不是吧,有#include<iostrema> 这样的么?
是不是错了
应该是<iostream>的
2011-10-14 22:04
快速回复:帮帮忙,重载运算符相关的
数据加载中...
 
   



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

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