| 1 | #include "e.h" |
| 2 | #include <iostream> |
| 3 | |
| 4 | E::E () |
| 5 | : m_count (0) |
| 6 | { |
| 7 | std::cout << "E::E" << std::endl; |
| 8 | } |
| 9 | void |
| 10 | E::Ref (void) const |
| 11 | { |
| 12 | std::cout << "E::Ref" << std::endl; |
| 13 | m_count++; |
| 14 | } |
| 15 | void |
| 16 | E::Unref (void) const |
| 17 | { |
| 18 | std::cout << "E::Unref" << std::endl; |
| 19 | m_count--; |
| 20 | if (m_count == 0) |
| 21 | { |
| 22 | delete this; |
| 23 | } |
| 24 | } |
| 25 | void |
| 26 | E::Do (void) |
| 27 | { |
| 28 | std::cout << "E::Do" << std::endl; |
| 29 | } |
| 30 | E::~E () |
| 31 | { |
| 32 | std::cout << "E::~E" << std::endl; |
| 33 | } |
| 34 | |
| 35 | E * |
| 36 | E::CreateWithoutRef (void) |
| 37 | { |
| 38 | std::cout << "E::CreateWithoutRef" << std::endl; |
| 39 | return new E (); |
| 40 | } |
| 41 | |
| 42 | E * |
| 43 | E::CreateWithRef (void) |
| 44 | { |
| 45 | std::cout << "E::CreateWithRef" << std::endl; |
| 46 | E *e = new E (); |
| 47 | e->Ref (); |
| 48 | return e; |
| 49 | } |