new 和 delete 用法
1、
这两个其实是 C++ 语言标准库的库函数,原型分别如下:
void *operator new(size_t); //allocate an object void *operator delete(void *); //free an object void *operator new[](size_t); //allocate an array void *operator delete[](void *); //free an array
2、基本数据类型
int *p = new int; delete p;
3、类
class *pA = new A(10); delete pA;
4、动态数组
string *psa = new string[10]; //array of 10 empty strings int *pia = new int[10]; //array of 10 uninitialized ints delete [] psa; delete [] pia;