V
vectorizor
Hi all,
I have a slight problem with the usage of function templates. It shoud
be really easy for you guys to explain me what's wrong.
I have one base class and 2 derived classes:
/*code*/
template <typename T> struct Image {...};
template <typename T> struct GrayImage : public Image<T> {...};
template <typename T> struct ColorImage : public Image<T> {...};
/*code*/
I am now trying to write a funtion to process images. The definition
is:
/*code*/
template <typename T, typename U> void func1(ColourImage<U> &input,
GrayImage<T> &output) {...}
/*code*/
Now I am tring to call this function as follow
/*code*/
GrayImage<f32> gray, tmp;
ColourImage<u8> color;
// ....
func1(color, gray);
/*code*/
When I try to compile that, the Visual Studio compilers complains that
"template parameter 'T' is ambiguous". Why is that? I do not
understand why.
It works though if I specify the template arguments explicitly though,
as follow
/*code*/
func1<f32, u8>(color, gray);
/*code*/
But ideally, I would like not to specify that. The thing that really
puzzles me is that I do not need to do that for a very similar
function.
/*code*/
template <typename T> void test(GrayImage<T> &input, GrayImage<T>
&output) {...}
// ...
GrayImage<f32> gray, tmp;
// ...
test(gray, tmp);
/*code*/
This works just fine. So what is the problem with the previous
function?!
Thanks in advance
Alex
I have a slight problem with the usage of function templates. It shoud
be really easy for you guys to explain me what's wrong.
I have one base class and 2 derived classes:
/*code*/
template <typename T> struct Image {...};
template <typename T> struct GrayImage : public Image<T> {...};
template <typename T> struct ColorImage : public Image<T> {...};
/*code*/
I am now trying to write a funtion to process images. The definition
is:
/*code*/
template <typename T, typename U> void func1(ColourImage<U> &input,
GrayImage<T> &output) {...}
/*code*/
Now I am tring to call this function as follow
/*code*/
GrayImage<f32> gray, tmp;
ColourImage<u8> color;
// ....
func1(color, gray);
/*code*/
When I try to compile that, the Visual Studio compilers complains that
"template parameter 'T' is ambiguous". Why is that? I do not
understand why.
It works though if I specify the template arguments explicitly though,
as follow
/*code*/
func1<f32, u8>(color, gray);
/*code*/
But ideally, I would like not to specify that. The thing that really
puzzles me is that I do not need to do that for a very similar
function.
/*code*/
template <typename T> void test(GrayImage<T> &input, GrayImage<T>
&output) {...}
// ...
GrayImage<f32> gray, tmp;
// ...
test(gray, tmp);
/*code*/
This works just fine. So what is the problem with the previous
function?!
Thanks in advance
Alex