主题:什么要调用三次析构函数
请大家看下为什么要调用三次析构函数?vc6下调试
#include<iostream>
using namespace std;
class XYZ
{
private:
int X;
int Y;
public:
XYZ()
{
X=0;
Y=0;
cout<<"Constructor 0.\n";
}
XYZ(int a,int b)
{
X=a;
Y=b;
cout<<"Cosntructor 2"<<endl;
}
XYZ(XYZ& p);
~XYZ()
{
cout<<"Destructor Called.\n";
}
int Xprint()
{
return X;
}
int Yprint()
{
return Y;
}
};
XYZ::XYZ(XYZ& p)
{
X=p.X;
Y=p.Y;
cout<<"Copy construcotr called."<<endl;
}
void fun(XYZ q)
{
int x;
int y;
x=q.Xprint()+100;
y=q.Yprint()+200;
XYZ R(x,y);
}
void main()
{
XYZ m;
fun(m);
}
#include<iostream>
using namespace std;
class XYZ
{
private:
int X;
int Y;
public:
XYZ()
{
X=0;
Y=0;
cout<<"Constructor 0.\n";
}
XYZ(int a,int b)
{
X=a;
Y=b;
cout<<"Cosntructor 2"<<endl;
}
XYZ(XYZ& p);
~XYZ()
{
cout<<"Destructor Called.\n";
}
int Xprint()
{
return X;
}
int Yprint()
{
return Y;
}
};
XYZ::XYZ(XYZ& p)
{
X=p.X;
Y=p.Y;
cout<<"Copy construcotr called."<<endl;
}
void fun(XYZ q)
{
int x;
int y;
x=q.Xprint()+100;
y=q.Yprint()+200;
XYZ R(x,y);
}
void main()
{
XYZ m;
fun(m);
}