add an extra constructor to use when the Create template cannot be used
This commit is contained in:
@@ -28,9 +28,14 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T>
|
||||
void Foo (void) {}
|
||||
|
||||
|
||||
class NoCount : public Object
|
||||
{
|
||||
public:
|
||||
NoCount (void (*fn) (void));
|
||||
NoCount (Callback<void> cb);
|
||||
~NoCount ();
|
||||
void Nothing (void) const;
|
||||
@@ -292,12 +297,22 @@ PtrTest::RunTests (void)
|
||||
callback ();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// as expected, fails compilation.
|
||||
{
|
||||
Ptr<const Object> p = Create<NoCount> (cb);
|
||||
Callback<void> callback = MakeCallback (&NoCount::Nothing, p);
|
||||
}
|
||||
// local types are not allowed as arguments to a template.
|
||||
{
|
||||
class B
|
||||
{
|
||||
public:
|
||||
B () {}
|
||||
};
|
||||
Foo<B> ();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -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 <typename U>
|
||||
@@ -378,6 +387,16 @@ Ptr<T>::Ptr (T *ptr)
|
||||
Acquire ();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<T>::Ptr (T *ptr, bool ref)
|
||||
: m_ptr (ptr)
|
||||
{
|
||||
if (ref)
|
||||
{
|
||||
Acquire ();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<T>::Ptr (Ptr const&o)
|
||||
: m_ptr (PeekPointer (o))
|
||||
|
||||
Reference in New Issue
Block a user