继承小试牛刀:虚方法virtual

#include<iostream>
using namespace std;
class Point
{
public:
    Point(double a=0,double b=0):xx(a),yy(b){}
   virtual double x(){return xx;}
   virtual double y(){return yy;}
private:
    double xx,yy;
};
class t_Point :public Point
{
public:
    t_Point(double a=0,double b=0,double c=0):Point(a,b),zz(c){}
    double z(){return zz;}
private:
    double zz;
};

//:public
int main()
{
    Point a(8,8);
    t_Point b(2,1,8);
    cout<<a.x()<<a.y()<<endl<<b.x()<<b.y()<<endl;
    cout<<b.z();
    return 0;
}

posted on 2017-04-05 11:23  TogetherLaugh  阅读(127)  评论(0编辑  收藏  举报