今天写NS3程序的时候发现老是报这个assert failed错误:
assert failed. cond="uid != 0", msg="Assert in TypeId::LookupByName: ns3::ndn::nrndn::SumoNodeSensor not found", file=../src/core/model/type-id.cc, line=539
terminate called without an active exception
我们知道, 写一个NS3的新模块,要写一个GetTypeId()的函数,以便NS3能够根据TypeID来查找一个类。然而我已经定义了该类的GetTypeId()静态函数 static TypeId tid = TypeId ("ns3::ndn::nrndn::NodeSensor"),但是就是在m_tid = TypeId::LookupByName (tid);阶段死活找不到这个名字。我就奇怪了,然后单步调试,发现在程序执行之前,每个类的GetTypeId 函数都要被执行一次,以在ns3中注册。是不是因为我没把NodeSensor这个类告诉ns3,导致它不知道要执行这个类的GetTypeId 函数呢?
我参考了其他模块的源码,果然,发现了每个含有GetTypeId 函数的源码前面都有一句宏:NS_OBJECT_ENSURE_REGISTERED
点进去,它的解释是:
/**
* \ingroup object
* \brief Register the class in the ns-3 factory.
*
* This macro should be invoked once for every class which
* defines a new GetTypeId method.
*
* If the class is in a name