[英]How to get the object of the module dynamically created in OMNet++ 4?
I'm a newbie in OMNet. 我是OMNet的新手。 In my project, I dynamically create a simple module, and I want to use the object created by this module. 在我的项目中,我动态创建了一个简单的模块,并且希望使用此模块创建的对象。 Does anyone can give me some help? 有人可以给我些帮助吗?
Source is here: 来源在这里:
cModuleType* moduleType = cModuleType::get("Person");
cModule *mod = moduleType->create("per", this->getParentModule());
mod->buildInside();
mod->scheduleStart(simTime());
mod->callInitialize();
job->mod = mod;
Basically, I want to find the object related to the "mod". 基本上,我想找到与“ mod”相关的对象。
Thank you 谢谢
I'm not sure what you mean "find" the object you created. 我不确定您的意思是“查找”您创建的对象。 You already have the object you created, you probably just need to cast it to do anything useful with it. 您已经拥有了创建的对象,您可能只需要将其强制转换即可对其执行任何有用的操作。
If you mean you want to operate on the module "mod", you can do this by casting "mod" to the module type which you've declared (say MyModule). 如果您想对模块“ mod”进行操作,则可以通过将“ mod”强制转换为已声明的模块类型(例如MyModule)来实现。
MyModule *my_mod = check_and_cast<MyModule *>(mod);
You can then define some public functions in the class of MyModule (usually MyModule.cc) that do whatever you want to do. 然后,您可以在MyModule类(通常是MyModule.cc)中定义一些公用函数,这些公用函数可以执行您想执行的任何操作。
MyModule::my_method() {some code}
If you've done this, in the current function, you can just go: 如果您已完成此操作,则可以在当前函数中执行以下操作:
my_mod->my_method();
I hope this answers your question. 我希望这回答了你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.