| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1160 人关注过本帖
标题:此题错在哪里?
只看楼主 加入收藏
louchenggang
Rank: 1
等 级:新手上路
帖 子:5
专家分:3
注 册:2017-9-27
结帖率:25%
收藏
已结贴  问题点数:5 回复次数:2 
此题错在哪里?
#include <iostream>
using namespace std;
class Point {
    private:
        int x;
        int y;
    public:
        Point() { };
、/*friend ostream & operator << (ostream & o,const Point & s);
    friend istream & operator >> (istream & is,const Point & s);
     
    ostream & operator <<(ostream & o,const Point & s)
    {
         o<<s.x<<s.y;
        return o;
    }
     
    istream & operator >> (istream & is,const Point & s)
    {
         is >>s.x>>s.y;
        return is;
    }
    注释部分是我修改部分,您看错在哪里?
     */
};
int main()
{
     Point p;
     while(cin >> p) {
         cout << p << endl;
    }
    return 0;
}
错误提示说 ostream & operator <<(ostream & o,const Point & s)只能有一个参数?
搜索更多相关主题的帖子: Point int operator const return 
2017-10-04 15:14
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:3 
把o放在重载<<的函数体内定义,不作为传参
2017-10-07 11:20
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:3 
程序代码:
#include <iostream>

class Point
{
public:
    Point() : x_(), y_()
    {
    }
    Point( int x, int y ) : x_(x), y_(y)
    {
    }

    friend std::ostream& operator<< ( std::ostream& os, const Point& pt )
    {
        return os << pt.x_ << ' ' << pt.y_;
    }
    friend std::istream& operator>> ( std::istream& is, Point& pt )
    {
        return is >> pt.x_ >> pt.y_;
    }
private:
    int x_, y_;
};

using namespace std;

int main( void )
{
    for( Point pt; cin>>pt; )
    {
        cout << pt << endl;
    }
    return 0;
}
2017-10-09 08:49
快速回复:此题错在哪里?
数据加载中...
 
   



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

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