Topic: Template argument matching
Author: robtcram@crl.com (Robert H. Cram)
Date: 1995/06/30 Raw View
I understand that the following code is defined not to work:
template<class T> void add(T a, long b);
// void add(int a, int b);
template,class T. void add(T a, long b)
{
T c = a + b;
}
static void addEm()
{
add(1, 2); // error here, int 2 doesn't match long
}
1) Why can't trivial conversions be applied?
2) How does adding the line that is commented out above (and adding no
further code anywhere else) resolve the problem? i.e. what template
function is generated? and in what order are conversions and template
function generation made.
Pointers to references are also welcome (the C++ ref man and "the c++
prog lang" didn't clear this up for me).
Bob Cram