正在加载图片...
例:有理数的加法 ex12_overload_member_01.cpp class Rational public: Rational(){x=0;y=1; Rational(int x,int y){this->x=x;this->y=y; Rational operator+(const Rational p); private: int x,yi }; RationalRational:operator+(const Rational&p) int newx x*p.yy*p.x; int newy y*p.y; return Rational(newx,newy); http://math.ecnu.edu.cn/~jypan 8 http://math.ecnu.edu.cn/~jypan 8 例:有理数的加法 class Rational { public: Rational() { x=0; y=1; } Rational(int x, int y) { this->x=x; this->y=y; } Rational operator+(const Rational & p); private: int x, y; }; Rational Rational::operator+(const Rational & p) { int newx = x*p.y + y*p.x; int newy = y*p.y; return Rational(newx, newy); } ex12_overload_member_01.cpp
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有