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) (→CMakeLists.txt) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | ==ClassFunctionPointer.cpp== |
<source lang="cpp"> | <source lang="cpp"> | ||
#include <boost/function.hpp> | #include <boost/function.hpp> | ||
Line 50: | Line 50: | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
− | Project( | + | Project(ClassFunctionPointer) |
− | ADD_EXECUTABLE( | + | ADD_EXECUTABLE(ClassFunctionPointer ClassFunctionPointer.cpp) |
− | + | ||
− | + | ||
− | + | ||
</source> | </source> |
Latest 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(ClassFunctionPointer) ADD_EXECUTABLE(ClassFunctionPointer ClassFunctionPointer.cpp)