介绍异常引发的类"指示分配请求不成功。
class bad_alloc : public exception {
bad_alloc();
virtual ~bad_alloc();
};
备注
what 返回的值是实现定义的 C 字符串。 成员函数不引发任何异常。
要求
新 <的页眉: >
命名空间: std
示例
// bad_alloc.cpp
// compile with: /EHsc
#include<new>
#include<iostream>
using namespace std;
int main() {
char* ptr;
try {
ptr = new char[(~unsigned int((int)0)/2) - 1];
delete[] ptr;
}
catch( bad_alloc &ba) {
cout << ba.what( ) << endl;
}
}
示例输出
bad allocation
要求
新 <的页眉: >