[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
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

  1. include <cassert>
  2. include <boost/function.hpp>
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); }


Code links



last edited (November 9, 2006) by bilderbikkel, Number of views: 1481, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.