C++拷贝构造函数问题

来源:百度知道 编辑:UC知道 时间:2024/05/05 20:29:05
//了解拷贝构造函数的用法
#include<iostream>
using namespace std;
class Point
{
public:
Point(int=0;int=0);
Point(const Point&);
void displayxy();
~Point();
private:
int X,Y;
};
Point::Point(int x,int y)
{
X=x;
Y=y;
cout<<"Constrctor is called";
displayxy();
}
Point::Point(const Point &p);
{
X=p.X;
Y=p.Y;
cout<<"Copy constructor is called";
displayxy();
}
Point::~Point()
{
cout<<"Destructor is called";
displayxy();
}
void Point::displayxy()
{
cout<<X<<Y<<endl;
}
Point func(Point p)
{
int x=10*2;
int y=10*2;
Point pp(x,y);
return pp;
}
int main()
{
Point p1(3,4);
Point p2=p1;
p2=func(p1);
return 0;
}
调试有一个错!!哪里错??

#include<iostream>
using namespace std;
class Point
{
public:
Point(int=0,int=0); // Point(int=0;int=0); 函数参数里面为什么要用分号?
Point(const Point&);
void displayxy();
~Point();
private:
int X,Y;
};

Point::Point(int x,int y)
{
X=x;
Y=y;
cout<<"Constrctor is called";
displayxy();
}

Point::Point(const Point &p) //Point::Point(const Point &p); 函数的实现~在函数后面要加分号吗~又不是申明~
{
X=p.X;
Y=p.Y;
cout<<"Copy constructor is called";
displayxy();
}

Point::~Point()
{
cout<<"Destructor is called";
displayxy();
}

void Point::displayxy()
{
cout<<X<<Y<<endl;
}

Point func(Point p)
{
int x=10*2;
int y=10*2;
Point pp(x,y);
return pp;
}

int