Help with template data type argument
Hi!
I am writing an image handling program, and have implemented the image class as a template class, to be able to choose more freely which data type I want the channels to be represented with.
So I have my template class
Code:
template <class T, uint NUM_CHANNELS>
class mp_image {
public:
static const size_t BPP = NUM_CHANNELS * sizeof(T); /* Bytes per pixel */
void *pixels;
uint width;
uint height;
uint pitch; /* pitch = number of bytes per line */
/* constructor */
mp_image(uint w, uint h);
/* destructor */
~mp_image();
};
Now comes the tricky part. I have declared a member function externally in another header file (this is a bluring function and I want every 'filter', and other manipulating function to be declared outside of the class declaration), it looks like this:
Code:
template<class T, uint NC, class T2>
mp_image<T, NC>::SquareBlur<T2>(uint radius);
I must have written something wrong, since the compile complains: expected constructor, destructor, or type conversion before '<' token. And it means the last of the '<' tokens, the one just before T2. Do you know how it should be?
Anyway, this is not the biggest problem. I need to have a second data type T2 for this function, since it needs a data type with the same precision as T, but one which is able to store values about the-number-of-pixels-in-the-picture times as high, because of the way the algorithm works. So, at least 20 - 24 bits more, a uint8 for example would preferably mean to send a uint32 as T2, and a float would mean a double. Now, is there any way to determine T2 automatically instead of having to provide it in each call, so that I could just type myImage.SquareBlur(rad) for example and it would figure out the type of T2 itself? Is it possible to create a lookup table where both the keys and the values are data types?