首页 > 学院 > 开发设计 > 正文

C++ 复制构造函数

2019-11-14 12:50:32
字体:
来源:转载
供稿:网友

、、待补充

#include<iostream> using std::cout;using std::endl;class Point{public: // constructor Point(int ix,int iy) :_Ix(ix) ,_Iy(iy){ cout<<"Point"<<endl; } // copy constructor Point() Point(const Point & rhs) :_Ix(rhs._Ix) ,_Iy(rhs._Iy){ cout<<"Point (const Point &) copy constructor"<<endl; } void PRint(){ cout<<"("<<this->_Ix <<","<<this->_Iy <<")"<<endl; }private: int _Ix=0; int _Iy=0;};int main(){ Point pt(1,3); pt.print(); Point pt2=pt; // call copy constructor pt2.print(); return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表