zoukankan      html  css  js  c++  java
  • 虚函数(单一继承)

     1 class Point {
     2 public:
     3     virtual ~Point();
     4     
     5     virtual Point & mult (float) = 0;
     6     //.....
     7     float x() const { return _x;}
     8     virtual float y() const {return 0;}
     9     virtual float z() const {return 0;}
    10     
    11 protected:
    12     Point( float x=0.0);
    13     float _x;
    14 };
    15 
    16 class Point2d : public Point{
    17 public:
    18     Point2d (float x=0.0, float y=0.0) : Point(x), _y(y){}
    19     
    20     ~Point2d();
    21     
    22     Point2d & mult (float);
    23     float y() const {return _y;}
    24 protected:
    25     float _y;
    26 };
    27 
    28 class Point3d : public Point2d{
    29 public :
    30     Point3d (float x=0.0,float y=0.0, float z=0.0): Point2d(x,y), _z(z){}
    31     ~Point3d();
    32     
    33     Point3d & mult(float);
    34     float z() const { return _z;}
    35 protected:
    36     float _z;
    37 };

     --未完,待续

  • 相关阅读:
    javaSE基础(三)
    javaSE基础(二)
    javaSE基础(一)
    文件目录爬虫
    前自增 与 后自增
    查找 与 排序 总结
    python 使用 grpc
    python3.7 安装 uwsgi
    go
    go
  • 原文地址:https://www.cnblogs.com/zhaoyaxing/p/8375722.html
Copyright © 2011-2022 走看看