Commit 0ef384ef by songxinkai

c++functional

parent fa95df52
#include <iostream>
#include <functional>
int print(int a){
std::cout << a << std::endl;
return 0;
}
int print_sum(int a, int b, int c){
std::cout << a+b+c << std::endl;
return 0;
}
class classA {
public:
void testPrint(int a){
std::cout << a << std::endl;
}
};
int main(){
std::function<int(int)> func1(print);
func1(11);
std::function<int(int)> func2([](int a) { std::cout << a << std::endl; return 0; }); // 2
func2(22);
std::function<int(int)> func3 = std::bind(print, std::placeholders::_1);
func3(33);
classA cla;
std::function<void(int)> func4 = std::bind(&classA::testPrint, &cla, std::placeholders::_1);
func4(44);
std::function<int(int, int)> func5 = std::bind(print_sum, 1, std::placeholders::_1, std::placeholders::_2);
func5(55, 1);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment