doc: add note regarding template classes and duplicate TypeId allocation

This commit is contained in:
Gabriel Ferreira
2023-10-28 15:03:23 -03:00
parent f6f3df14da
commit 9b7088d363

View File

@@ -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
++++++++++++++++++++++++