doc: add note regarding template classes and duplicate TypeId allocation
This commit is contained in:
@@ -385,6 +385,29 @@ every class that defines a new GetTypeId method, and it does the actual
|
||||
registration of the class into the system. The :ref:`Object-model` chapter
|
||||
discusses this in more detail.
|
||||
|
||||
Note: Template classes should both export the instantiated template and call
|
||||
``NS_OBJECT_TEMPLATE_CLASS_DEFINE (TemplateClass, TemplateArgument);``
|
||||
to prevent the same template from being instantiated more than a single
|
||||
time in different modules. This prevents errors such as
|
||||
``Trying to allocate twice the same uid: TemplateClass<TemplateArgument>``.
|
||||
|
||||
An example for the ``CounterCalculator<uint32_t>``::
|
||||
|
||||
//.h file
|
||||
namespace ns3
|
||||
{
|
||||
extern template class CounterCalculator<uint32_t>;
|
||||
}
|
||||
//.cc file
|
||||
#include <ns3/.h file>
|
||||
namespace ns3
|
||||
{
|
||||
NS_OBJECT_TEMPLATE_CLASS_DEFINE (CounterCalculator, uint32_t);
|
||||
}
|
||||
|
||||
More details can be found in `issue #761 <https://gitlab.com/nsnam/ns-3-dev/-/issues/761>`_.
|
||||
|
||||
|
||||
Including External Files
|
||||
++++++++++++++++++++++++
|
||||
|
||||
|
||||
Reference in New Issue
Block a user