C++primer 6.7節練習

來源:互聯網
上載者:User

標籤:pac   prim   ace   cstring   dex   out   clu   code   ring   

練習6.54

1 int fun(int, int);2 typedef int (*pf) (int, int);3 vector<pf> a;
 1 int funAdd(int i, int j) 2 { 3     return i + j; 4 } 5 int funDel(int i, int j) 6 { 7     return i - j; 8 } 9 int funMul(int i, int j)10 {11     return i * j;12 }13 int funDiv(int i, int j)14 {15     return i / j;16 }17 18 19 int main()20 {21     typedef int (*pf) (int, int);22     vector<pf> a(2);23     a[0] = funAdd;24     a[1] = funDel;25     a[2] = funMul;26     a[3] = funDiv;27     cout << a[0](1, 2) << endl;28     cout << a[1](8, 3) << endl;29     system("pause");30     return 0;31 }

練習6.56

 1 #include <cstring> 2 #include <vector> 3 #include <stdexcept> 4 #include "factmain.h" 5 using namespace std; 6  7 int funAdd(int i, int j) 8 { 9     return i + j;10 }11 int funDel(int i, int j)12 {13     return i - j;14 }15 int funMul(int i, int j)16 {17     return i * j;18 }19 int funDiv(int i, int j)20 {21     return i / j;22 }23 24 25 int main()26 {27     typedef int (*pf) (int, int);28     vector<pf> a(4);29     a[0] = funAdd;30     a[1] = funDel;31     a[2] = funMul;32     a[3] = funDiv;33     cout << a[0](1, 2) << endl;34     cout << a[1](8, 3) << endl;35     cout << a[2](2, 3) << endl;36     cout << a[3](144, 12) << endl;37     system("pause");38     return 0;39 }

C++primer 6.7節練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.