头文件
# include<iostream>
# include“stdlib.h” //exit
using namespace std;
# define TRUE 1
# define FALSE 0
# define ERROR 0
# define OK 0
assert
// 不在范围内
if(i<1||i>L.length)
return ERROR
...
return OK
错误代码
malloc/free
if(!L.elem)
exit(OVERFLOW);
http:
int* p = new int[SIZE];
if ( p == 0 )
return -1;
try {
int* p = new int[SIZE];
} catch ( const bad_alloc& e ) {
return -1;
}
# include <iostream>
using namespace std;
int main()
{
int * i = NULL;
i = new(nothrow) int[1000];
if (i == NULL)
{
cout << "bad allocation" << endl;
return -1;
}
return 0;
}