#include<iostream>
using namespace std;
class TPoint4 //声明类TPoint
{
int x, y; //声明数据成员
public:
TPoint4(int x1, int y1){//构造函数
x=x1; y=y1;
}
TPoint4(const TPoint4 &obj){//构造函数
x=obj.x; y=obj.y;
}
void dispoint(){
cout<<"("<<x<<", "<<y<<")"<<endl;
}
};
int main()
{
TPoint4 a(12, 6), b(a);
cout<<"First point: ";
a.dispoint();
cout<<"Second point: ";
b.dispoint();
return 0;
}
C++ 复制构造函数示例
最新推荐文章于 2024-06-07 21:06:43 发布