我在 Visual Studio 2010 C++ 编译器中遇到了奇怪的行为。以下代码编译但在执行后抛出“调试断言失败”并显示消息:
“_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)”
在 GCC 下编译运行流畅。是我的错吗?
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned int uint;
class Foo {
vector<int*> coll;
public:
void add(int* item) {
coll.push_back(item);
}
~Foo() {
for (uint i = 0; i < coll.size(); ++i) {
delete coll[i];
coll[i] = NULL;
}
}
};
int main()
{
Foo foo;
foo.add(new int(4));
Foo bar = foo;
return 0;
}