我有一个模板类(Node
是 BST 中的内部类)。现在是释放内存的时候了;鉴于键或值(或两者)可能是指针,我必须弄清楚如何释放它们。
看一个例子:
~Node( void )
{
if ( is_pointer< TValue >( Value ) )
{
delete Value;
Value = NULL;
}
if ( is_pointer< TComparable >( Key ) )
{
delete Key;
Key= NULL;
}
}
该is_pointer< T >
函数背后的实现是有效的(取自此处),但是只要我在 Key 或 Value 上按 delete,我就会得到以下信息:
Error 13 error C2440: 'delete' : cannot convert from 'esc::Shader' to 'void *' c:\programming\c++\git\escalator\engine\engine\searchtree.hpp 131
Error 14 error C2440: 'delete' : cannot convert from 'esc::ShaderComparable' to 'void *' c:\programming\c++\git\escalator\engine\engine\searchtree.hpp 137
Error 12 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) c:\programming\c++\git\escalator\engine\engine\searchtree.hpp 130
我试过static_cast
, dynamic_cast
,reinterpret_cast
等,但这些似乎都不起作用。
什么是好的解决方案?