src/core/ptr.h
changeset 225 dad23ccd9e6c
parent 223 80f1c6b76999
child 227 482a61824ef4
--- a/src/core/ptr.h	Mon Dec 18 13:28:29 2006 +0100
+++ b/src/core/ptr.h	Mon Dec 18 14:25:33 2006 +0100
@@ -53,6 +53,7 @@
   };
   static uint32_t *AllocCount (void);
   static void DeallocCount (uint32_t *count);
+  friend class Ptr<const T>;
 public:
   /**
    * Create an empty smart pointer
@@ -93,6 +94,10 @@
   template <typename T1, typename T2>
   inline friend bool operator != (T1 const *lhs, Ptr<T2> &rhs);
 
+  template <typename T1, typename T2>
+  inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p);
+
+
   /**
    * \returns raw pointer
    *
@@ -233,7 +238,7 @@
 T *
 Ptr<T>::Remove (void) 
 {
-  assert (m_ptr.m_count == 1);
+  assert ((*m_count) == 1);
   T *retval = m_ptr;
   m_ptr = 0;
   return retval;
@@ -265,6 +270,14 @@
   return lhs != rhs.m_ptr;
 }
 
+template <typename T1, typename T2>
+Ptr<T1>
+const_pointer_cast (Ptr<T2> const&p)
+{
+  return Ptr<T1> (const_cast<T1 *> (p.m_ptr));
+}
+
+
 }; // namespace ns3
 
 #endif /* PTR_H */