2

我正在尝试使用以下代码导航到 2 级模块:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();

for (cSubModIterator iter(*grantParentmod); !iter.end();iter++)
    EV<<"Current module is "<< iter()->getFullName() <<endl;

输出是: -

Current module is notificationBoard
Current module is mobility
Current module is udpApp[0]
Current module is udpApp[1]
Current module is udp
Current module is networkLayer
Current module is routingTable
Current module is interfaceTable
Current module is wlan[0]

但是,当我直接尝试通过以下代码访问 udpApp[0] 时:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();

cModule* udpmod = parentmod->getParentModule()->getSubmodule("udpApp[0]");
EV<<"Current module is "<< udpmod->getFullName() <<endl;

模拟在运行时结束并出现以下错误:模拟以退出代码终止:139,这意味着分段错误。但是,如果我使用任何其他模块,例如“mobility”而不是“udpApp [0]”,那么它可以正常工作。

任何人都可以帮我找出解决这种情况的可能方法。

4

1 回答 1

1

您收到此错误是因为您试图取消引用 Null 指针。你得到一个空指针,因为给 getSubmodule 的模块名称“xyz[123]”不存在。它不存在,因为方括号中的数字不是子模块名称的一部分,而是它在模块向量中的索引。名称和索引必须在对getSubmodule的调用中单独指定。

于 2015-06-08T23:37:21.410 回答