diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 10e63c606..cee3f59e2 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -28,9 +28,14 @@ namespace ns3 { +template +void Foo (void) {} + + class NoCount : public Object { public: + NoCount (void (*fn) (void)); NoCount (Callback cb); ~NoCount (); void Nothing (void) const; @@ -292,12 +297,22 @@ PtrTest::RunTests (void) callback (); } + #if 0 // as expected, fails compilation. { Ptr p = Create (cb); Callback callback = MakeCallback (&NoCount::Nothing, p); } + // local types are not allowed as arguments to a template. + { + class B + { + public: + B () {} + }; + Foo (); + } #endif diff --git a/src/core/ptr.h b/src/core/ptr.h index f5a52292e..5d3ce46a6 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -81,7 +81,16 @@ public: * same, so that object is deleted if no more references to it * remain. */ - Ptr (T *ptr); + Ptr (T *ptr); + /** + * \param ptr raw pointer to manage + * \param ref if set to true, this method calls Ref, otherwise, + * it does not call Ref. + * + * Create a smart pointer which points to the object pointed to by + * the input raw pointer ptr. + */ + Ptr (T *ptr, bool ref); Ptr (Ptr const&o); // allow conversions from T to T const. template @@ -378,6 +387,16 @@ Ptr::Ptr (T *ptr) Acquire (); } +template +Ptr::Ptr (T *ptr, bool ref) + : m_ptr (ptr) +{ + if (ref) + { + Acquire (); + } +} + template Ptr::Ptr (Ptr const&o) : m_ptr (PeekPointer (o))