Difference between revisions of "CPP/Boost/ClassFunctionPointer"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with "==Function.cpp== <source lang="cpp"> #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class MyClass { private: double Update1() { std::cou...") |
Daviddoria (Talk | contribs) (→Function.cpp) |
||
Line 1: | Line 1: | ||
− | == | + | ==ClassFunctionPointer.cpp== |
<source lang="cpp"> | <source lang="cpp"> | ||
#include <boost/function.hpp> | #include <boost/function.hpp> |
Revision as of 15:37, 12 May 2015
ClassFunctionPointer.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)