bad_alloc — Klasabad_alloc Class
Klasa zawiera opis zgłoszonego wyjątku, aby wskazać, że żądanie alokacji nie powiodło się.The class describes an exception thrown to indicate that an allocation request did not succeed.
SkładniaSyntax
class bad_alloc : public exception {
bad_alloc();
virtual ~bad_alloc();
bad_alloc(const bad_alloc&);
bad_alloc& operator=(const bad_alloc&);
const char* what() const override;
};
UwagiRemarks
Wartość zwrócona przez what
to ciąg języka C zdefiniowany przez implementację.The value returned by what
is an implementation-defined C string. Żadna z funkcji Członkowskich nie zgłasza żadnych wyjątków.None of the member functions throw any exceptions.
PrzykładExample
// 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