core: Add a static assert to prevent misuse of Create<>() function
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* @file
|
||||
@@ -427,6 +428,8 @@ struct EventMemberImplObjTraits<Ptr<T>>
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
class Object;
|
||||
|
||||
/*************************************************
|
||||
* friend non-member function implementations
|
||||
************************************************/
|
||||
@@ -435,6 +438,8 @@ template <typename T, typename... Ts>
|
||||
Ptr<T>
|
||||
Create(Ts&&... args)
|
||||
{
|
||||
static_assert(!std::is_base_of_v<Object, T>,
|
||||
"Use CreateObject() instead of Create() for Object subclasses");
|
||||
return Ptr<T>(new T(std::forward<Ts>(args)...), false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user