|
Last change
on this file since 47 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
958 bytes
|
| Line | |
|---|
| 1 | /* Copyright Bruno da Silva de Oliveira 2003. Use, modification and |
|---|
| 2 | distribution is subject to the Boost Software License, Version 1.0. |
|---|
| 3 | (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 4 | http:#www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef SMART_PTR_H |
|---|
| 8 | #define SMART_PTR_H |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | #include <memory> |
|---|
| 12 | #include <boost/shared_ptr.hpp> |
|---|
| 13 | |
|---|
| 14 | namespace smart_ptr { |
|---|
| 15 | |
|---|
| 16 | struct C |
|---|
| 17 | { |
|---|
| 18 | int value; |
|---|
| 19 | }; |
|---|
| 20 | |
|---|
| 21 | inline boost::shared_ptr<C> NewC() { return boost::shared_ptr<C>( new C() ); } |
|---|
| 22 | |
|---|
| 23 | struct D |
|---|
| 24 | { |
|---|
| 25 | boost::shared_ptr<C> Get() { return ptr; } |
|---|
| 26 | void Set( boost::shared_ptr<C> c ) { ptr = c; } |
|---|
| 27 | private: |
|---|
| 28 | boost::shared_ptr<C> ptr; |
|---|
| 29 | }; |
|---|
| 30 | |
|---|
| 31 | inline std::auto_ptr<D> NewD() { return std::auto_ptr<D>( new D() ); } |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | // test an abstract class |
|---|
| 35 | struct A |
|---|
| 36 | { |
|---|
| 37 | virtual int f() = 0; |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | struct B: A |
|---|
| 41 | { |
|---|
| 42 | virtual int f(){ return 1; } |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | inline boost::shared_ptr<A> NewA() { return boost::shared_ptr<A>(new B()); } |
|---|
| 46 | inline int GetA(boost::shared_ptr<A> a) { return a->f(); } |
|---|
| 47 | |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | #endif |
|---|
Note: See
TracBrowser
for help on using the repository browser.