I declared simple structure:
struct Heap {
int size;
int *heap_array;
};
When Im trying to create table, where k is int from stdin:
Heap *rooms = new Heap[k];
I got:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
Using int literally everything is ok:
Heap *rooms = new Heap[0];
How to declare such table?
Chances are your value read from
stdinwas invalid. If the read failed you might have some default value in it like 2^32.