出问题的代码在这一段
int pinCount = pATempl->m_PinCount;
int* arrIndexCount =new int[pinCount];
ZeroMemory(arrIndexCount, pinCount);
测了很久才知道问题出在这里。一开始测试打印arrIndexCount里面的数值,发现都是些未定义的值。
想不明白啊,网上说ZeroMemory不能用来初始化类,因为他会把虚函数的指针也置为零,好吧,这是个知识点。可俺这不是类啊。
难道new出来的不能用ZeroMemory初始化?
也不可能
后来发现坑爹
是ZeroMemory的字节参数算错了,我靠!!!!!
pinCount,这是数组的大小,不是字节数。应该要再乘以 sizeof(int)
int pinCount = pATempl->m_PinCount;
int* arrIndexCount =new int[pinCount];
ZeroMemory(arrIndexCount, pinCount * sizeof(int));
本文讲述了在使用 ZeroMemory 函数时的一个常见错误:未正确计算字节数。通过一个实例展示了如何由于误解 ZeroMemory 的参数而导致内存初始化失败,并给出了正确的解决方法。

被折叠的 条评论
为什么被折叠?



