/*
* My code snippet (code.cpp)
*/
for(item = 0; item < m_NumSetShipsAtt.size(); item++)
{
// create attacking objects; for every ship 1 object
obj = FillObj(m_NumSetShipsAtt[item].Type, ATTER, m_NumSetShipsAtt[item].OwnerID);
if(m_NumSetShipsAtt[item].OwnerID != CurrPl)
CurrPl = m_NumSetShipsAtt[item].OwnerID;
for(size_t o = 0; o < m_NumSetShipsAtt[item].Num; o++) {
try {
m_AttObj->push_back(obj);
}
catch (bad_alloc& xa) {
cerr << "In catch block, so an exception occurred: " << xa.what() << endl;
cerr << "ships added so far: " << o << endl;
cerr << "m_AttObj's size is: " << m_AttObj->size() << endl;
cerr << "m_AttObj's capacity is: " << m_AttObj->capacity() << endl;
cerr << "m_AttObj's max size is: " << m_AttObj->max_size() << endl << endl;
cerr << "Exiting...";
return 1;
}
}
}
/*
* m_AttObj declaration snippet (code.h)
*/
vector<Obj>* m_AttObj, *m_DefObj;
/*
* vector declaration snippets (libstd++'s stl_vector.h)
*/
template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
class vector : protected _Vector_base<_Tp, _Alloc>
{
// ... much more
/** Returns the size() of the largest possible %vector. */
size_type
max_size() const
{ return _M_get_Tp_allocator().max_size(); }
// ... much more again
|