CC_CALLBACK之間的區別

來源:互聯網
上載者:User

標籤:

#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__)

①__selector__:綁定要回調的函數名,注意要加上命名空間:函數名

②__target__:綁定一個對象

③std::placeholders::_1:綁定的函數裡除了第一個參數之外的參數,就是調用函數傳參時要傳第一個參數,如果_selector_後面有參數,則在用CC_CALLBACK時要綁定

④std::placeholders::_2:依次類推

CC_CALLBACK的作用是讓_target_對象用_selector_函數時綁定第0/1/2/3個參數後面參數的值,例如

int add (int i, int j){return i+j;}auto func = CC_CALLLBACK_1(add, this, 10);

 

這時得到的func就相當與func(int i, int j = 10),用的時候可以用func(15),

cout << func(15) << endl; // 結果是15 + 10 = 25,即cout << 25

 

 

  

CC_CALLBACK之間的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.