我有一个模板函数,它接受两种数据类型 - int和double并返回一个较小的数据,现在,我如何推断出这个函数返回的类型?现在,我正在丢失小数点后的部分.
#include <iostream>
using namespace std;
template <class First, class Second>
First smaller(First a, Second b){
return (a < b ? a : b);
}
int main () {
int x = 100;
double y = 15.5;
cout<< smaller (x,y) << endl;
}
Run Code Online (Sandbox Code Playgroud)