I have a funtion which allocates memory to a pointer as following:
void initializeImageBuffer(unsigned char **image, int w, int h)
{
if (*image != NULL)
delete[] *image;
*image = new unsigned char[w * h];
}
now I want to generalize the argument type (unsigned char/int/double) using function template. Thats what I did:
template<typename T, int, int>
void initializeImageBuffer(T **image, int w, int h)
{
if (*image != NULL)
delete[] *image;
*image = new T[w * h];
}
But there is an error using the function like:
unsigned char* image;
initializeImageBuffer(&image, 200, 200);
"There is no instance of overloading function with these argument types. The Arguments types are (unsigned char**, int, int)."