Last change
on this file since 29 was
29,
checked in by landauf, 17 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
702 bytes
|
Line | |
---|
1 | // Copyright (C) 2001-2003 |
---|
2 | // William E. Kempf |
---|
3 | // |
---|
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
---|
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | #include <boost/thread/thread.hpp> |
---|
8 | #include <boost/ref.hpp> |
---|
9 | #include <iostream> |
---|
10 | |
---|
11 | class factorial |
---|
12 | { |
---|
13 | public: |
---|
14 | factorial(int x) : x(x), res(0) { } |
---|
15 | void operator()() { res = calculate(x); } |
---|
16 | int result() const { return res; } |
---|
17 | |
---|
18 | private: |
---|
19 | int calculate(int x) { return x <= 1 ? 1 : x * calculate(x-1); } |
---|
20 | |
---|
21 | private: |
---|
22 | int x; |
---|
23 | int res; |
---|
24 | }; |
---|
25 | |
---|
26 | int main() |
---|
27 | { |
---|
28 | factorial f(10); |
---|
29 | boost::thread thrd(boost::ref(f)); |
---|
30 | thrd.join(); |
---|
31 | std::cout << "10! = " << f.result() << std::endl; |
---|
32 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.