在删除之前测试C ++中的void指针 [英] Test for void pointer in C++ before deleting
本文介绍了在删除之前测试C ++中的void指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C ++中有一个数组:
Player ** playerArray;
这是在它的类的构造函数中初始化的。
在析构函数中,我有:
delete playerArray;除了通过Valgrind测试程序时,它表示有一些调用要删除一个void指针:
<
操作员delete(void *)
我想在调用delete之前测试playerArray是否为void指针,以避免此错误。
有人知道如何做? $
解决方案
也许你的意思是 delete [] playerArray
。如果指针是数组,而不是单个实例,则需要 []
。
I have an array in C++:
Player ** playerArray;
which is initialized in the constructor of the class it is in.
In the destructor I have:
delete playerArray;
except when testing the program through Valgrind it says that there are some calls to delete to a void pointer:
operator delete(void*)
I want to test whether the playerArray is a void pointer before calling delete to avoid this error.
Does anyone know how to do this?
解决方案
Perhaps you meant delete [] playerArray
. You need the []
if the pointer is an array, not a single instance.
这篇关于在删除之前测试C ++中的void指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文