5,530
社区成员
发帖
与我相关
我的任务
分享
// length_error.cpp
// compile with: /EHsc /GR
#include <vector>
#include <iostream>
using namespace std;
template<class _Ty>
class stingyallocator : public allocator<_Ty>
{
public:
template <class U>
struct rebind { typedef stingyallocator<U> other; };
_SIZT max_size( ) const
{
return 10;
};
};
int main( )
{
try
{
vector<int, stingyallocator< int > > myv;
for ( int i = 0; i < 11; i++ ) myv.push_back( i );
}
catch ( exception &e )
{
cerr << "Caught " << e.what( ) << endl;
cerr << "Type " << typeid( e ).name( ) << endl;
};
}
//Sample Output
//Caught vector<T> too long
//Type class std::length_error