1 | //****** Header 1 **********
|
---|
2 |
|
---|
3 | #include <boost/intrusive_ptr.hpp>
|
---|
4 | #include <boost/detail/atomic_count.hpp>
|
---|
5 |
|
---|
6 | using boost::intrusive_ptr;
|
---|
7 |
|
---|
8 | class Foo;
|
---|
9 | namespace boost
|
---|
10 | {
|
---|
11 | void intrusive_ptr_add_ref(Foo* psFoo);
|
---|
12 | void intrusive_ptr_release(Foo* psFoo);
|
---|
13 | };
|
---|
14 |
|
---|
15 | class SomeClass
|
---|
16 | {
|
---|
17 | boost::detail::atomic_count reference_count;
|
---|
18 | friend void ::boost::intrusive_ptr_add_ref(Foo* psFoo);
|
---|
19 | friend void ::boost::intrusive_ptr_release(Foo* psFoo);
|
---|
20 | };
|
---|
21 |
|
---|
22 | namespace boost
|
---|
23 | {
|
---|
24 | void intrusive_ptr_add_ref(Foo* psFoo)
|
---|
25 | {
|
---|
26 | ++(psFoo->reference_count);
|
---|
27 | }
|
---|
28 |
|
---|
29 | void intrusive_ptr_release(Foo* psFoo)
|
---|
30 | {
|
---|
31 | --(psFoo->reference_count);
|
---|
32 | }
|
---|
33 | };
|
---|
34 |
|
---|
35 | //****** Header 2 **********
|
---|
36 |
|
---|
37 | // include Header 1
|
---|
38 | #include <boost/intrusive_ptr.hpp>
|
---|
39 | using boost::intrusive_ptr;
|
---|
40 |
|
---|
41 | // Gcc 4.7.0 and clang 3.1 need the following two lines to compile this example
|
---|
42 | //using boost::intrusive_ptr_add_ref;
|
---|
43 | //using boost::intrusive_ptr_release;
|
---|
44 |
|
---|
45 | class Bar
|
---|
46 | {
|
---|
47 | intrusive_ptr<Foo> psFoo;
|
---|
48 | public:
|
---|
49 | Bar(intrusive_ptr<Foo> foo): psFoo(foo) { }
|
---|
50 | };
|
---|
51 |
|
---|
52 | //****** Source 2 **********
|
---|
53 | // include Header 2
|
---|
54 |
|
---|
55 | int main(int, const char**)
|
---|
56 | {
|
---|
57 | return 0;
|
---|
58 | }
|
---|