如果我只启用双精度和整数,那么它是 4 个函数。但我想启用所有数据类型(int long float double unsigned numbers 等)这怎么可能?
#include <iostream>
using namespace std;
double diff(int num1, int num2) {
return double(num1-num2);
}
double diff(int num1, double num2) {
return double(num1)-num2;
}
double diff(double num1, int num2) {
return num1-double(num2);
}
double diff(double num1, double num2) {
return num1-num2;
}
int main() {
int a = 10;
double b = 4.4;
cout << diff(a, b) << endl;
return 0;
}