C++?е?delete??delete[]??????
???????????? ???????[ 2014/2/21 11:47:53 ] ????????net ???? ???????
????????C++?е?delete??delete[]????????????????????????????£??ó???????????????????????
????C++??????????????? new ???????????????????????? delete???????? new[] ??????????????????????? delete[]??
???????? new[] ?? delete[]???????????????????(1) ??????????????????????(2) ???????????????????
??????????????
#include <iostream>
#include<string>
using namespace std;
class T {
public:
T() { cout << "constructor" << endl; }
~T() { cout << "destructor" << endl; }
};
int main()
{
//??????”???????????“??string???????new??delete
const int NUM = 3;
string *x=new string(10??'3');
cout<<hex<<x<<endl;
delete x;
//??????”?????????????“??class T???????new??delete
T* p1 = new T;
cout << hex << p1 << endl;
// delete[] p1;
delete p1;
//?????”?????????????“??class T[NUM]???????new[]??delete[]
T* p2 = new T[NUM];
cout << p2 << endl;
delete[] p2;
}
|
????????????????????????????? delete p1 ?? delete[] p1 ??????????????????н?????£?
?????????н????????????????delete p1 ????????????У???? p1[0] ???????????????????????????????? p1[1]??p1[2] ?????е???????????????????????????????????????? delete[]????????????????ж???????????????????????????
??????????????????????????????????????????????????????? delete ?? delete[] ???????????????????????????飬????? delete[]?????? new ?????????????? delete ?????? delete[] ??????
????????????????????????new ?? delete??new[] ?? delete[] ?????á?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11