Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <functional>
- class Thing {
- public:
- void move( float x ) {
- std::cout << "moving with " << x << std::endl;
- }
- };
- class Other {
- public:
- using CallbackFunction = std::function<void(float)>;
- public:
- void go() {
- mCallback( 42 );
- }
- void setCallback( CallbackFunction func ) {
- mCallback = func;
- }
- protected:
- std::function<void(float)> mCallback;
- };
- int main() {
- using namespace std;
- auto thing = make_shared<Thing>();
- auto other = make_shared<Other>();
- other->setCallback( std::bind( &Thing::move, thing.get(), std::placeholders::_1 ) );
- other->go();
- return 0;
- }
Add Comment
Please, Sign In to add comment