Skip to content

Instantly share code, notes, and snippets.

@keisukeYamagishi
Last active January 29, 2017 04:31
Show Gist options
  • Save keisukeYamagishi/b7fa11d131acb8b04eef967011e0ab6d to your computer and use it in GitHub Desktop.
Save keisukeYamagishi/b7fa11d131acb8b04eef967011e0ab6d to your computer and use it in GitHub Desktop.
#include <functional>
#include <iostream>
//////////////////////////
// call back variable
//////////////////////////
typedef std::function<void(int num, char* ch)> func;
typedef std::function<void(int num, char* ch, int num2)> func2;
void callSecond(int num, char* ch, const func2& f2){
std::cout << "call callSecond !!!" << std::endl;
f2(num,ch,10);
}
void call(int num, char* c, func f){
std::cout << "call back dude!!" << std::endl;
f(num, c);
}
//////////////////////////
// call back function
//////////////////////////
void function_back(int num, char* ch){
std::cout << "num variable :: " << num << "char* ch :: >> " << ch << std::endl;
}
int main(){
std::function<void(int num, char* ch)> call_back;
call_back = function_back;
call_back(1, " yamada death ");
call(20, "call back",[=](int num, char* c){std::cout << num << c << std::endl;});
callSecond(20, "konyaga_yamada" ,[=](int num, char* ch,int num2){std::cout << num << ch << std::endl;});
return 0;
}
#include <functional>
#include <iostream>
//////////////////////////////////////
// call back function
//
//////////////////////////////////////
void function_back(int num, char* ch){
std::cout << "num variable :: " << num << "char* ch :: >> " << ch << std::endl;
}
int main(){
std::function<void(int num, char* ch)> call_back;
call_back = function_back;
std::function<void(int num, char* ch)> call_b;
call_b = [=](int num, char* ch){printf("char :: %s\nnum :: %d",num, ch );};
call_back(1, " yamada death ");
return 0;
}
@keisukeYamagishi
Copy link
Author

ramda C++ study
c++

@keisukeYamagishi
Copy link
Author

compile:
c++ -std=c++11 c_b.cpp -o c_b

@keisukeYamagishi
Copy link
Author

compile:

c++ -std=c++11 cp2.cpp -o cp2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment