赞
踩
上节《Modern C++ std::bind的实现原理-CSDN博客》主要讲的是原理,本节举个例子并画图帮助理解。
上程序:
- #include <functional>
- #include <iostream>
-
- // A function taking three arguments
- void printValues(int a, double b, const std::string& str) {
- std::cout << "Values: " << a << ", " << b << ", " << str << std::endl;
- }
-
- int main() {
- auto boundFunction11 = std::bind(printValues, std::placeholders::_2, 3.14, std::placeholders::_1);
- boundFunction11("hello",1);
- return 0;
- }
这里我故意颠倒了两个参数的顺序,先_2再_1,希望下面这张解释原理的图能“一图胜千言” :

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。