c++怎么用new创建的对象的数组,又怎样删除对象

2024-12-18 20:28:02
推荐回答(4个)
回答1:

class A
{
};
void func()
{
A *p=new A[100]; //创建100 个对象
.
.
.
.
delete []p; // [] 号 一定要有的
}

回答2:

int main()
{
char *p=new char[5];
strcpy(p,"DING");
CName one(p);
delete []p;
cout< return 0;
}

回答3:

int *a=new int;
char *b=new char; //初值为1
int *c=new int[100]; //创建100个动态对象

delete a;
delete b;
delete []c;

回答4:

A aa = new A[100];
delete[] aa;

能看懂吧?