#include <iostream.h>
#include <stdlib.h>
#include <new.h>
void newError();
int main()
{
set_new_handler(newError);
char * c1 = new char[2];
cout << "First allocation worked properly.\n";
char * c2 = new char[64000]; // 잘못된 할당(너무 많은 문자가 할당)
cout << "Second allocation worked properly.\n";
delete [] c1;
delete [] c2;
return 0;
}
void newError()
{
// 에러 메시지 출력 후 프로그램 종료
cerr << "Cannot allocate the requested memory.\n";
exit(1);
}
#include <stdlib.h>
#include <new.h>
void newError();
int main()
{
set_new_handler(newError);
char * c1 = new char[2];
cout << "First allocation worked properly.\n";
char * c2 = new char[64000]; // 잘못된 할당(너무 많은 문자가 할당)
cout << "Second allocation worked properly.\n";
delete [] c1;
delete [] c2;
return 0;
}
void newError()
{
// 에러 메시지 출력 후 프로그램 종료
cerr << "Cannot allocate the requested memory.\n";
exit(1);
}
덧글을 달아 주세요