Omnet access method of another submodule error - no matching function for call to ‘check_and_cast(cModule*&)’

匿名 (未验证) 提交于 2019-12-03 01:46:01

问题:

Error: no matching function for call to ‘check_and_cast(cModule*&)’

I am trying to use the current position from another module "mobility" with n class type MassMobility.

cModule* parentmod = getParentModule();  cModule* mobilitymod = parentmod->getParentModule()->getSubmodule("mobility"); EV<<"Current module is "<<mobilitymod->getFullName() <<endl;  MassMobility* mobility = check_and_cast<MassMobility *>(mobilitymod); mobility->getCurrentPosition();

I am getting compile time error :- no matching function for call to ‘check_and_cast(cModule*&)’. But still I am able to get the functions from the mobility object as shown in last line. Can anybody please suggest me how can I correct it.

回答1:

Well I figure out the problem. First thing I needed to add header file of mobility module in my current sub module to get the definitions. So I included-

#include "MassMobility.h" #include "StationaryMobility.h"

then in code I did following modification:-

cModule* parentmod = getParentModule(); cModule* mobilitymod = parentmod->getParentModule()->getSubmodule("mobility"); MassMobility* massMobilityMod = dynamic_cast<MassMobility*>(mobilitymod); EV<<"Current position is <<"massMobilityMod->getCurrentPosition();

So the reason for the errors is the lack of definitions, which is provided by the header files in this solution.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!