Effective C+:std::bind小特性.
725 ワード
#include <iostream>
#include <functional>
void function(int& number)
{
number = 50;
}
using functionType = void(*)(int&);
int main()
{
//case 1:
int n1 = 10;
auto f1 = std::bind(function, 10);
f1();
std::cout<<n1<<std::endl; // : 10.
//case 2:
int n2 = 20;
auto f2 = std::bind(function, std::ref(n2));
f2();
std::cout<<n2<<std::endl; // : 50.
//case 3:
int n3 = 30;
auto f3 = std::bind(function, n3);
f3();
std::cout<< n3 <<std::endl; // : 30
return 0;
}