声明struct表时出现Std::bad_alloc错误
std::bad_alloc error when declaring struct table
我声明了简单的结构:
struct Heap {
int size;
int *heap_array;
};
当我试图创建表,其中k
是int从stdin:
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。
相关文章:
- 使用来自 Excel VBA 的 C++ dll 时"Bad DLL calling convention" - 如何解决?
- C++17 编解码器在将标准::字符串转换为标准::字符串时抛出"bad conversion"
- 对于代理容器上的迭代器来说,"least bad implementation"可能是什么?
- 组件对象模型 (COM):IMalloc::Alloc 在哪里分配内存?
- 获取错误:在抛出"std::bad::alloc"的实例后终止调用 what(): std::bad_alloc
- 为什么 GetSystemMetrics (SM_CXVIRTUALSCREEN) 返回'bad'值?
- 将 lambda 传递给 STL 集时出错"bad function call"
- 新的 C++14 位分隔符处"Bad Character" Eclipse Oxygen 错误
- 使用 #define 被认为是"bad practice"吗?
- "400 Bad request"使用 OpenSSL BIO 进行请求时
- CGAL:Hausdorff距离不良Alloc
- 解密文件AES_256_CBC返回"bad decrypt"错误
- 在C++流中,eof(),fail(),bad()和good()有什么区别
- C STD ::初始化类对象中的Alloc错误错误
- make / gcc:"bad build"的可能原因是什么?
- 什么是地址0xbaddc0dedeadbead "Bad decode dead bead"
- 在多线程环境中,什么可能导致"bad file descriptor"?
- 尝试解决HackerBank上的BFS挑战时出现错误的alloc异常
- "std::vector"在调整大小时引发"bad allocation"异常
- 尝试使用 execp、dup2 和管道实现 shell,挂起或"bad file descriptor"