求一个C++程序输出题,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/05 03:22:45
#include <iostream.h>
class B
{
int x,y;
public:
B( )
{ x=y=0; cout<<”Constructor1”<<endl; }
B(int i)
{ x=i; y=0; cout<<”Constructor2”<<endl; }
B(int i,int j)
{ x=i; y=j; cout<<”Constructor3”<<endl; }
~B( )
{ cout<<”Destructor”<<endl; }
void print()
{
cout<<”x=”<<x<<”,y=”<<y<<endl;
}
};
void main()
{
B *ptr;
ptr=new B[3];
ptr[0]=B();
ptr[1]=B(50);
ptr[2]=B(12,13);
for(int i=0;i<3;i++)
ptr[i].print();
delete[] ptr;
}

Constructor1
Constructor1
Constructor1
Constructor1
Destructor
Constructor2
Destructor
Constructor3
Destructor
x=0,y=0
x=50,y=0
x=12,y=13
Destructor
Destructor
Destructor
Press any key to continue

Constructor1
Constructor1
Constructor1
Constructor1
Destructor
Constructor2
Destructor
Constructor3
Destructor
x=0,y=0
x=50,y=0
x=12,y=13
Destructor
Destructor
Destructor

好久没做过这种题了
我怎么认为是:
Constructor2
Constructor1

Constructor3
哪个环节错了?