以下の内容はhttps://toburau.hatenablog.jp/entry/20090208/1234106182より取得しました。


newに失敗したときNULLを返す

C++でnewに失敗したときは例外が投入されるが、NULLを返すようにすることもできる。

ポインタ変数 = new(nothrow) 型;

nothrowを付ければ例外ではなくNULLを返すようになる。

#include <iostream>
using namespace std;

void main()
{
    int* p;

    for(int i=0; i<1000; i++)
    {
        p = new(nothrow) int[100000000];
        if (!p) return;
        cout << p << endl;
    }
}



以上の内容はhttps://toburau.hatenablog.jp/entry/20090208/1234106182より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14