#include<bits/stdc++.h>
using namespace std;
class Test
{
private:
int num;
int* p=nullptr;
public:
Test()
{
cout<<"无参构造"<<endl;
}
Test(int n)
{
cout<<"有参构造"<<endl;
p=new int[n];
}
~Test()
{
if(p) delete[]p;
cout<<"析构函数"<<endl;
}
};
int main()
{
int* p=new int;
cout<<*p<<endl;
delete p;
int* p1=new int(3);
cout<<*p1<<endl;
delete p1;
int* p2=new int[3];
cout<<p2[0]<<' '<<p2[1]<<' '<<p2[2]<<endl;
delete[]p2;
int* p3=new int[3]{1,2,3};
cout<<p3[0]<<' '<<p3[1]<<' '<<p3[2]<<endl;
delete[]p3;
Test* t=new Test;
delete t;
Test* t1=new Test();
delete t1;
Test* t2=new Test[3];
delete[]t2;
Test* t3=new Test[3]{Test(),Test(1),Test(2)};
delete[]t3;
return 0;
}