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 
NewC()21 inline boost::shared_ptr<C> NewC() { return boost::shared_ptr<C>( new C() ); }
22 
23 struct D
24 {
GetD25     boost::shared_ptr<C> Get() { return ptr; }
SetD26     void Set( boost::shared_ptr<C> c ) { ptr = c; }
27 private:
28     boost::shared_ptr<C> ptr;
29 };
30 
NewD()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 {
fB42     virtual int f(){ return 1; }
43 };
44 
NewA()45 inline boost::shared_ptr<A> NewA() { return boost::shared_ptr<A>(new B()); }
GetA(boost::shared_ptr<A> a)46 inline int GetA(boost::shared_ptr<A> a) { return a->f(); }
47 
48 }
49 
50 #endif
51