求大侠!一个关于函数模板实例化的有关问题

求大侠!一个关于函数模板实例化的问题
rt,比如说,一个函数模板
template<class T>
void k(const T&,const T&);
int a=1;
double b=2.0;
k(a,b);
为什么通不过编译呢?
b虽然是浮点型,但函数形参是const,不管是const int&或 const double &都能接受double 啊?

------解决方案--------------------

一般而论,不会转换实参以匹配已有的实例化,相反,会产生新的实例。
除了产生新的实例化之外,编译器只会执行两种转换:
1、const 转换: 接受 const 引用或 const 指针的函数可以分别用非 const
对象的引用或指针来调用,无须产生新的实例化。如果函数接受非引用类
型,形参类型实参都忽略 const,即,无论传递 const 或非 const 对象
给接受非引用类型的函数,都使用相同的实例化。
2、数组或函数到指针的转换:如果模板形参不是引用类型,则对数组或函数
类型的实参应用常规指针转换。数组实参将当作指向其第一个元素的指
针,函数实参当作指向函数类型的指针。
非模板实参:进行常规转换

------解决方案--------------------
参考7楼
------解决方案--------------------
作为标准控,我用c++标准回答你。

C++标准规定,模版实例化过程中,对于函数的两个参数,会分别推测其类型(注意一个词:independently),就是说第一个参数的推测和第二个参数的推测是分开的,而不是和在一起推测。

如果2个参数推测出来的类型不同,则实例化失败。

void k(const T&,const T&);
第一个T推测为int,第二个T推测为double。所以失败。

Type deduction is done independently for each P/A pair, and the deduced template argument values are then combined. If type deduction cannot be done for any P/A pair, or if for any pair the deduction leads to more than one possible set of deduced values, or if different pairs yield different deduced values, or if any template argument remains neither deduced nor explicitly specified, template
argument deduction fails.