C++ error: terminate called after throwing an instance of ‘std::bad_alloc’
This code has 3 holes: First hole: int numEntries. Later you do: ++numEntries; You increment unspecified value. Not sure if it’s UB, but still bad. Second and third hole: And numEntries has unspecified value (first hole). You use it to initialize length and size – that is Undefined Behaviour. But let’s assume it is just some big number – you allocate memory … Read more