【发布时间】:2015-02-03 05:48:35
【问题描述】:
在标题中
class foo
{
unsigned int *Indices;
unsigned int *func(int var);
};
in CPP
unsigned int *foo::func(int var)
{
Indices = new unsigned int[((unsigned)var *3)];
//do math.
return Indices;
}
在初始化索引数组时,我在 malloc.c 内部得到了休息
这里发生了什么?为什么我要休息?
我有一种感觉,这是因为int var 在编译时是未知的。它是否正确?
我也尝试过使用幻数而不是 var 但问题仍然存在
【问题讨论】:
-
您所要做的就是在
[]中指定一个整数,例如new int[3] -
您的代码看起来不错。尝试发布MCVE。
-
要重现问题,您不需要更多信息。我在 malloc.c 中中断的代码区域是.. 第 57 行 __forceinline void * __cdecl _heap_alloc (size_t size) { if (_crtheap == 0) { _FF_MSGBANNER(); /* 写入运行时错误横幅 / _NMSG_WRITE(_RT_CRT_NOTINIT); / 写消息/ __crtExitProcess(255); / 通常 _exit(255) */ } return HeapAlloc(_crtheap, 0, size ? size : 1);
-
你可能已经在程序的其他地方造成了堆损坏
-
请注意,您的代码中没有
int*数组。
标签: c++ arrays pointers break unsigned-integer