清华大学C++程序设计第八讲多态性和虚函数.pptVIP

  • 2
  • 0
  • 约7.75千字
  • 约 42页
  • 2017-05-23 发布于广东
  • 举报

清华大学C++程序设计第八讲多态性和虚函数.ppt

清华大学C程序设计第八讲多态性和虚函数

* * * * * * * * * * * * * * * * * * * * * * #includeiostream using namespace std; class Point { public: Point(double i, double j) {x=i; y=j;} double Area() const{ return 0.0;} private: double x, y; }; class Rectangle:public Point { public: Rectangle(double i, double j, double k, double l); double Area() const {return w*h;} private: double w,h; }; 静态绑定例 * Rectangle::Rectangle(double i, double j, double k, double l) :Point(i,j) { w=k; h=l; } void fun(Point s) { coutArea=s.Area()endl; } int main() { Rectangle rec(3.0, 5.2, 15.0, 25.0); fun(rec); } 运行结果: Area=0 * #includeiostream

文档评论(0)

1亿VIP精品文档

相关文档