#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);
}
 
2006/11/28 20:24 2006/11/28 20:24

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요