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

来源:互联网 发布:牡丹江信息网源码 编辑:程序博客网 时间:2024/05/29 14:11

运行环境: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;}

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

0 0