• 虚函数(单一继承)


     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 };

     --未完,待续

  • 相关阅读:
    Linux定时任务调度
    Linux组管理和权限管理
    Linux压缩和解压缩类指令
    leetcode:Compare Version Numbers
    leetcode:Valid Palindrome
    Majority Element
    Min Stack
    leetcode:Intersection of Two Linked Lists(两个链表的交叉点)
    leetcode:Factorial Trailing Zeroes
    leetcode:Rotate Array
  • 原文地址:https://www.cnblogs.com/zhaoyaxing/p/8375722.html
Copyright © 2020-2023  润新知