繁体   English   中英

声明结构表时std :: bad_alloc错误

[英]std::bad_alloc error when declaring struct table

我声明了简单的结构:

struct Heap {
  int size;
  int *heap_array;
};

当我试图创建表时,其中k是来自stdin的int:

Heap *rooms = new Heap[k];

我有:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

实际上使用int一切正常:

Heap *rooms = new Heap[0];

如何声明这样的表?

stdin读取的值很可能无效。 如果读取失败,则可能会有一些默认值,例如2 ^ 32。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM