Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/function/example/bind1st.cpp @ 28

Last change on this file since 28 was 12, checked in by landauf, 17 years ago

added boost

File size: 658 bytes
RevLine 
[12]1// Boost.Function library examples
2
3//  Copyright Douglas Gregor 2001-2003. Use, modification and
4//  distribution is subject to the Boost Software License, Version
5//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org
9
10#include <iostream>
11#include <boost/function.hpp>
12#include <functional>
13
14struct X {
15  X(int val) : value(val) {}
16
17  int foo(int x) { return x * value; }
18
19  int value;
20};
21
22
23int
24main()
25{
26  boost::function<int (int)> f;
27  X x(7);
28  f = std::bind1st(std::mem_fun(&X::foo), &x);
29
30  std::cout << f(5) << std::endl; // Call x.foo(5)
31  return 0;
32}
Note: See TracBrowser for help on using the repository browser.