[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppBoostFunction
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppBoostFunction
(C++) boost::function
The Boost function library enables you to store function pointers in an easier way.Example using boost::function and plain function pointers
int func1(const int& x) { return x; } int func2(const int& x) { return x*x; } int main() { //Using boost::function boost::function1<int,const int&> f; //boost::function1 as function takes only 1 argument f = func1; assert(f(3)==3); f = func2; assert(f(4)==16); //Using function pointers int(*pFunc)(const int&); pFunc = func1; assert(pFunc(3)==3); pFunc = func2; assert(pFunc(4)==16); }
- include <cassert>
- include <boost/function.hpp>
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
