| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 396 人关注过本帖
标题:继承问题在程序最后,为啥xy不能继承
只看楼主 加入收藏
唐兵
Rank: 2
来 自:四川泸州合江
等 级:论坛游民
帖 子:150
专家分:12
注 册:2012-12-1
结帖率:82.05%
收藏
已结贴  问题点数:10 回复次数:2 
继承问题在程序最后,为啥xy不能继承
#include <iostream>
using namespace std;
class Point
{
public:
    //Point(int a,int b);
    friend ostream & operator<<(ostream &output,Point &p );
    void getxy();
    int  x,y;
};
/*Point::Point(int a,int b)
    {
        x=a;
        y=b;
    }*/
void Point::getxy()
{
    cout<<"input x,y:"<<endl;
    cin>>x>>y;
}
class Circle:public Point
{
public:
    friend ostream & operator<<(ostream &output,Point &p );
    //Circle(int a,int b,int r1);
    int area();
    void getr();
    int r;
};
//Circle::Circle(int a,int b,int r1):Point(a,b),r(r1){}
void Circle::getr()
{
    cout<<"input r:"<<endl;
    cin>>r;
}
int Circle::area()
{
    return 3.14*r*r;
}
class Cyinder:public Circle
{
public:
    int h;
};
ostream & operator<<(ostream &output,Circle &C )
{
    output<<C.x<<endl<<C.y<<endl<<C.area()<<endl;
    return output;
}
ostream & operator<<(ostream &output,Point &p )
{
    output<<p.x<<endl<<p.y<<endl;
    return output;
}
int main()
{
    Point o;
    o.getxy();
cout<<o;//为啥有歧义,该怎样改呢
    Circle c;
    c.getr();
    cout<<c;//为啥xy的值不能继承。该怎样改呢
    return 0;                  
}
搜索更多相关主题的帖子: friend public include 
2013-06-04 14:11
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:4 
如果一段代码千疮百孔,有无数的基础知识错误的话,最好系统的重新学一遍。
2013-06-04 15:52
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:4 
回复 2楼 rjsp
顶...

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-06-04 21:06
快速回复:继承问题在程序最后,为啥xy不能继承
数据加载中...
 
   



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

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