简体   繁体   English

如何获取在OMNet ++ 4中动态创建的模块的对象?

[英]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.

相关问题 如何在OMNet ++中将动态模块连接到静态模块 - How to connect dynamic module to static module in OMNet++ 如何在buttonclick上获取动态创建的文本框的值 - how to get the value of a dynamically created textbox on buttonclick omn​​et ++ Inet-模拟动态访问点行为 - omnet++ Inet - Simulating dynamic access point behaviour Silverlight 2:在动态创建的对象上INotifyPropertyChanged? - Silverlight 2: INotifyPropertyChanged on dynamically created object? 如何获取动态创建的线性布局的标签及其子ImageView - how to get tag of dynamically created linear layout and it's child ImageView 如何获取/设置动态创建的文本框的值 - how to get/set value of dynamically created text box 如何获取在casperjs中动态创建的图像的img src? - How to get the img src , of the images created dynamically in casperjs? 如何在 JQuery 中获取动态创建的单选按钮的值 - How do I get value of a dynamically created radio button in JQuery 如何获取输入类型 = 文件的值并将其显示在动态创建的图像上? - How to get value of input type = file and display it on a dynamically created image? 如何获取动态创建的选择列表组件的选定值 - How to get the selected value of a dynamically created selectlist component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM