OJ——构造函数和析构函数

来源:互联网 发布:王婉茹 黄翔 知乎 编辑:程序博客网 时间:2024/06/06 09:37
#include <iostream>using namespace std;//将程序需要的其他成份写在下面,只提交begin到end部分的代码//******************** begin ********************class Complex{private:    double real,imag;public:    Complex(double r,double i)    {        real=r;        imag=i;        cout<<"("<<real<<","<<imag<<"i)"<<" is constructed!"<<endl;        cout<<"("<<real<<","<<imag<<"i)"<<" is copy constructed!"<<endl;    }    ~Complex ()    {        cout<<"destructed!"<<endl;    }};//********************* end ********************int main(){double real,image;cin>>real>>image;Complex c1(real,image);Complex c2=c1;return 0;}

0 0
原创粉丝点击