CPP/Boost/Function
From ProgrammingExamples
Function.cpp
#include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class MyClass { private: double Update1() { std::cout << "Update1" << std::endl; } double Update2() { std::cout << "Update2" << std::endl; } public: boost::function< double() > Update; void SetUpdateMethod(int method) { if(method == 1) { this->Update = boost::bind(&MyClass::Update1,this); } if(method == 2) { this->Update = boost::bind(&MyClass::Update2,this); } } }; int main () { MyClass a; a.SetUpdateMethod(1); a.Update(); a.SetUpdateMethod(2); a.Update(); return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(Function) ADD_EXECUTABLE(Function Function.cpp)