首页 > 编程 > C++ > 正文

C++ Primer(第五版) 6.7练习综合版

2019-11-06 08:04:34
字体:
来源:转载
供稿:网友
//C++ PRimer(第五版) 6.7练习综合版 #include<iostream>#include<vector>using namespace std;using pfunc = int(*)(int, int);int sum(int,int);int subtract(int, int);//subtract 减 //学编程可以学英语int consult(int, int);// consult 商int product(int, int);//product  积int sum(int a, int b){    return (a + b);}int subtract(int a, int b){    return (a - b);}int consult(int a, int b){    if (!b)        return 0;    return (a / b);}int product(int a, int b){    return (a*b);}int main(){    vector<pfunc> a =    {        sum,        subtract,        consult,        product    };    for (auto fun : a)//auto 其实为pfunc C++11 限定for        cout << fun(4, 2) << endl;    system("pause");    return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选