Line | |
---|
1 | // Copyright (C) 2001-2003 |
---|
2 | // William E. Kempf |
---|
3 | // |
---|
4 | // Permission to use, copy, modify, distribute and sell this software |
---|
5 | // and its documentation for any purpose is hereby granted without fee, |
---|
6 | // provided that the above copyright notice appear in all copies and |
---|
7 | // that both that copyright notice and this permission notice appear |
---|
8 | // in supporting documentation. William E. Kempf makes no representations |
---|
9 | // about the suitability of this software for any purpose. |
---|
10 | // It is provided "as is" without express or implied warranty. |
---|
11 | |
---|
12 | #include <boost/thread/thread.hpp> |
---|
13 | #include <boost/ref.hpp> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | class factorial |
---|
17 | { |
---|
18 | public: |
---|
19 | factorial(int x) : x(x), res(0) { } |
---|
20 | void operator()() { res = calculate(x); } |
---|
21 | int result() const { return res; } |
---|
22 | |
---|
23 | private: |
---|
24 | int calculate(int x) { return x <= 1 ? 1 : x * calculate(x-1); } |
---|
25 | |
---|
26 | private: |
---|
27 | int x; |
---|
28 | int res; |
---|
29 | }; |
---|
30 | |
---|
31 | int main() |
---|
32 | { |
---|
33 | factorial f(10); |
---|
34 | boost::thread thrd(boost::ref(f)); |
---|
35 | thrd.join(); |
---|
36 | std::cout << "10! = " << f.result() << std::endl; |
---|
37 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.