Re: argument deduction for function template
vectorizor wrote:
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> {...};
Note the spelling of 'ColorImage'.
/*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,
Note the spelling of the type of the first argument.
GrayImage<T> &output) {...}
/*code*/
Now I am tring to call this function as follow
/*code*/
GrayImage<f32> gray, tmp;
ColourImage<u8> color;
Not the spelling of the type and the variable here. Please try to
stick to naming your things _consistently_.
This goes again toward the argument why code should NOT be typed into
the message. *Copy and paste* your code!!!
// ....
func1(color, gray);
/*code*/
When I try to compile that, the Visual Studio compilers
Which ones? VC++ 2005 seems to compile it correctly.
complains that
"template parameter 'T' is ambiguous". Why is that? I do not
understand why.
Because the compiler[s] you're using is/are buggy?
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?!
No problem. But if you have to use the compiler[s] you are using,
stick to your work-around.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask