c8_759208593
深度探索 多态类型与非多态类型 运行时类型识别 虚函数动态绑定的实现原理 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #includeiostream using namespace std; class Point { public: Point(double x, double y) : x(x), y(y) { } double area() const { return 0.0; } private: double x, y; }; class Rectangle: public Point { public: Rectangle(double x, double y, double w, double h); double area() const { return w * h; } private: double w, h; }; 静态绑定例 * Rectangle::Rectangle(double x, double y, double w, double h) :Point(x, y), w(w), h(h) { } void fun(const Point s) { cout Area = s.area() endl;
原创力文档

文档评论(0)