Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
Last active December 21, 2015 10:18
Show Gist options
  • Save yasuharu519/213307b4709662e60df2 to your computer and use it in GitHub Desktop.
Save yasuharu519/213307b4709662e60df2 to your computer and use it in GitHub Desktop.
#include <functional>
#include <iostream>
#include <string>
class Foo
{
public:
Foo(std::function<int(std::string, std::string, std::string)> fFunction) : fnCallback{fFunction} {}
int Call() { return fnCallback("first", "second", "third"); }
protected:
std::function<int(std::string, std::string, std::string)> fnCallback;
};
class Bar
{
public:
static int Function(std::string s1, std::string s2, std::string s3)
{
std::cout << s1 << s2 << s3 << std::endl;
return 0;
}
};
int main(int /*nArgc*/, char* /*paszArgv*/ [])
{
using namespace std::placeholders;
auto fn = std::bind(Bar::Function, _1, _2, _3);
Foo oFoo(fn);
oFoo.Call();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment