Topic: ????? Templates in the FORMAL parameter list ?????
Author: mvriesen@bonnou.eng.uci.edu (Mark Vriesenga)
Date: 7 Jun 1994 20:48:18 GMT Raw View
Hi Netters,
I have a small question about the use of templates that I hope someone will help me with. I have created a template image class (for image processing applications) called VIMAGE<TYPE>. So far, everything is wonderful and I don't have any problems with instantiating and using the corresponding image objects. However, I am wondering how to pass an image object (of any type including: BYTE, int, ...) into a nontemplate function. For example, I am allowed to write an image Add function as:
int Image_AddConstant(VIMAGE<ULONG> far *srcimg, float c)
{
.
.
.
return(ErrorCode);
}
or ...
template <class TYPE> int Image_AddConstant(VIMAGE<TYPE> far *srcimg, float c)
{
.
.
.
return(ErrorCode);
}
but this is somewhat painful. In the first case, I would have to write an overloaded Image_AddConstant() funtion for each image type. In the second case, the compiler will create an instance of the function for each instance called for in the code thereby creating an unncecessarily large amount of code. What I want to do is something like:
int Image_AddConstant(VIMAGE far *srcimg, float c)
{
.
.
.
return(ErrorCode);
}
where Image_AddConstant() can rely on the image objects to handle themselves and their addociated pixel i/o. This would cause the compiler to generate only one copy of the code for the Image_AddConstant() function. So my BIG question is how to pass a template-instantiated object into a function. Is this possible?
(Note: Someone has recently told me that multiple instantiations of a template function is handled through a union and so it will not add significantly redundant code to the .exe file. Is this correct?)
Thanks,
Mark Vriesenga
mvriesen@sloth.eng.uci.edu