《C++语言程序设计·中国水利水电版》AB第8章:多态性.pptVIP

  • 4
  • 0
  • 约1.36万字
  • 约 43页
  • 2017-05-23 发布于广东
  • 举报

《C++语言程序设计·中国水利水电版》AB第8章:多态性.ppt

《C语言程序设计·中国水利水电版》AB第8章:多态性

例8.7 (续三) class CCircle:public CShape { private: CPoint Center; int Radius; public: CCircle(CPoint ctr, int r, char *c):CShape(c),Center(ctr) { Radius = r; } virtual void Draw() { cout Draw a Circle at center ( Center.GetX() , ; cout Center.GetY() ) with radius Radius and color ; PrintColor(); } }; 第8章 多态性 例8.7 (续四) void main() { CShape *ps[3]; CShape s(Red); CPoint p1(10,10), p2(100,100),p3(50,50); CLine l(p1,p2,Green); CCircle c(p3, 20, Black); ps[0] = s; ps[1] = l; ps[2] = c; for(int i=0; i3; i++) ps[i]-Draw(); } 第8章 多态性 程序运行结果为: Draw a Shape. The c

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档