第9讲 复习 派生和继承,多态性与虚函数课件.ppt

第9讲 复习 派生和继承,多态性与虚函数课件.ppt

// triangle.h #ifndef _triangle_h_ #define _triangle_h_ #include shape.h class Triangle: public shape { double m_height; public: Triangle(double length, double height ): shape(length) { m_height=height; } virtual char* Name( ) const { return “三角形”; } virtual double Area( ) const { return 0.5*m_measure * m_height; } }; #endif 虚函数——特殊成员函数:编译阶段,编译器无法确定要调用的子类的虚函数地址, 而是为它生成虚函数表(存放同名,同参,同返回值的虚函数地址)。 程序运行时,根据对象实际

文档评论(0)

1亿VIP精品文档

相关文档