I am facing compilation error in the below code. I am writing a function to free memory in C++
template<class T> inline void kill(T& v)
{
free(v);
v=0;
}
I am calling this function for freeing Class object and sometime to free a string and getting below error.
Error 1 'void free(void *)' : cannot convert argument 1 from 'const char *' to 'void *'
Error 2 'void free(void *)' : cannot convert argument 1 from 'Cstring ' to 'void *'
If I change the code like below then no error.
template<class T> inline void kill(T& v)
{
free((void*)v);
v=0;
}
Any other better solution for this?