c++编程试题

2025-04-03 07:19:25
推荐回答(2个)
回答1:

#include
int function(int &a, int &b)
{
return a % b;
}
double function(double &a, double &b)
{
return a / b;
}

int main()
{
using std::cout;
int a = 3, b = 7;
double c = 3.0, d = 7.0;
int(*pi)(int &, int &) = function;
double(*pd)(double &, double &) = function;
cout <<"求商函数地址function:"<< pd<< '\n' <<"求余函数地址function:"<< pi << endl;
cout << "调用求余函数:\t"< cout << "调用求商函数:\t" << function(c, d) << endl;
return 0;
}
因为简单,全部保函一起了,没有分开头文件之类,只是告诉你了函数的重载,其实,函数的重载,用模板函数最好。

回答2:

这根本就没什么难度吧,思路题目给的都一清二楚了