标题:继承问题在程序最后,为啥xy不能继承
取消只看楼主
唐兵
Rank: 2
来 自:四川泸州合江
等 级:论坛游民
帖 子:150
专家分:12
注 册:2012-12-1
结帖率:82.05%
已结贴  问题点数:10 回复次数:0 
继承问题在程序最后,为啥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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-414488-1-1.html




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

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