Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int main(void) { const char* kung = "Foo"; delete []kung; }
在这段代码中,为什么我会得到以下内容debug assert failed block_type_is_valid?
debug assert failed block_type_is_valid
是因为 kung 指针指向内存中无法解除分配的常量字符串吗?
因为您不能delete使用字符串文字(这是kung指向的内容)。
delete
kung
您也不能删除自动存储字符串(所以它不是真正的文字部分):
char kung[] = "Foo"; delete []kung; //still illegal
只有delete[]您分配的内存new[]。
delete[]
new[]