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

强颜欢笑 提交于 2019-12-25 03:32:07

问题


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.



来源:https://stackoverflow.com/questions/30225285/omnet-access-method-of-another-submodule-error-no-matching-function-for-call-t

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