Reputation: 168
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.
Upvotes: 1
Views: 1132
Reputation: 168
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.
Upvotes: 1