Difference between revisions of "CPP/Boost/Function"
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::cout <…') |
Daviddoria (Talk | contribs) |
||
Line 3: | Line 3: | ||
#include <boost/function.hpp> | #include <boost/function.hpp> | ||
#include <boost/bind.hpp> | #include <boost/bind.hpp> | ||
− | + | ||
#include <iostream> | #include <iostream> | ||
− | + | double Function0() | |
{ | { | ||
− | + | return 1; | |
− | + | } | |
− | + | ||
− | + | double Function1(const int a) | |
− | + | { | |
− | + | return a+1; | |
− | + | } | |
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
int main () | int main () | ||
{ | { | ||
− | + | boost::function<double ()> FunctionPointer0 = &Function0; | |
− | + | boost::function<double (const int)> FunctionPointer1 = &Function1; | |
− | + | ||
− | |||
− | |||
− | |||
return 0; | return 0; | ||
} | } | ||
+ | |||
</source> | </source> | ||
Line 52: | Line 32: | ||
Project(Function) | Project(Function) | ||
ADD_EXECUTABLE(Function Function.cpp) | ADD_EXECUTABLE(Function Function.cpp) | ||
− | |||
− | |||
</source> | </source> |
Latest revision as of 15:37, 12 May 2015
Function.cpp
#include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> double Function0() { return 1; } double Function1(const int a) { return a+1; } int main () { boost::function<double ()> FunctionPointer0 = &Function0; boost::function<double (const int)> FunctionPointer1 = &Function1; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(Function) ADD_EXECUTABLE(Function Function.cpp)