---------------
Christof Meerwald@freec++.prog

home
> prog
>> freecpp
>>> bad alloc

translate to German (by SYSTRAN)

New Throws std::bad_alloc

> bad_alloc.cpp:

#include <new>


int main(int argc, char *argv[])
{
  try
  {
    char *a = new char[1024*1024*1024];
    char *b = new char[1024*1024*1024];
    char *c = new char[1024*1024*1024];
    char *d = new char[1024*1024*1024];

    return !(a && b && c && d);
  }
  catch (const std::bad_alloc &e)
  {
    return 0;
  }

  return 1;
}
---------------

This Web page is licensed under the Creative Commons Attribution - NonCommercial - Share Alike License. Any use is subject to the Privacy Policy.

Revision: 1.2, cmeerw.org/prog/freecpp/bad_alloc.html
Last modified: Mon Sep 03 18:20:50 2018
Christof Meerwald <cmeerw@cmeerw.org>
XMPP: cmeerw@cmeerw.org