我是 OMNeT++ 新手,我正在为一个项目使用 Inet 框架。 我想在应用程序模块中访问 Mac 模块以获取变量。我在 omnet++ 手册中看到了这一点。
cModule *targetModule = getParentModule()->getSubmodule("foo");
Foo *target = check_and_cast<Foo *>(targetModule);
target->doSomething();
还有这个
cModule *app = module->getModuleByPath(".app[3]"); // note leading dot
cModule *gen = module->getModuleByPath(".app[3].gen");
所以我将它们结合起来,我的表述如下:
cModule *macModule = cModule::getModuleByPath("TestNetwork.wlan[0].mac");
updatedMac *target = check_and_cast<updatedMac *>(macModule);
var = target->getVar();
路径来自ini文件。
我收到此错误:
<!> check_and_cast(): Cannot cast nullptr to type 'inet::updatedMac *' -- in module (inet::ApplicationApp) TestNetwork.host[1].app[0] (id=85), at t=0.305s, event #250
我是不是把路径弄错了?那么如何写从applicationlayer模块到linklayer模块的路径。
我真的需要帮助。
最佳答案
路径不正确,
cModule *macModule = cModule::getModuleByPath("TestNetwork.host[1].wlan[0].mac");
还有其他选择。
auto modNode = getContainingNode(this);
auto macModule = modNode->module->getSubmodule("wlan", 0);
if (macModule != nullptr) {
}
关于c++ - 获取其他模块访问变量的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65324175/