Rev | Line | |
---|
[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 | |
---|
| 14 | struct X { |
---|
| 15 | X(int val) : value(val) {} |
---|
| 16 | |
---|
| 17 | int foo(int x) { return x * value; } |
---|
| 18 | |
---|
| 19 | int value; |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | int |
---|
| 24 | main() |
---|
| 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.