首页 > 编程 > C++ > 正文

C++实例---构造函数的重载

2019-11-08 18:52:28
字体:
来源:转载
供稿:网友

运行环境:macOS shell 代码:

#include <iostream>#include <iomanip>#include <string>using namespace std;class point{PRivate: double fx, fy;public: point(); point(double x, double y); void showpoint();};point::point(){ fx = 0.0; fy = 0.0;}point::point(double x, double y = 5.5){ fx = x; fy = y;}void point::showpoint(){ cout<<fx<<" "<<fy<<endl;}int main (){ point p1; cout<<"the fx and fy of p1 : "; p1.showpoint(); point p2(10); cout<<"the fx and fy of p2 : "; p2.showpoint(); point p3(1.1,2.0); cout<<"the fx and fy of p3 : "; p3.showpoint(); return 0;}

运行结果: 这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选