Reputation: 31
I'm simulating network in Omnet++, with INET framework. I want to get the position (coordination x & y) of node. So I do this code:
cModule *host = getContainingNode(this);
IMobility *mobility = check_and_cast<IMobility *>(host->getSubmodule("mobility"));
... = mobility -> getCurrentPosition();
But, when I ran the simulation, I got this error
check_and_cast(): cannot cast nullptr to type 'inet::IMobility *'
Can you explain to me this error? As I see, if the simulator notify that, so host->getSubmodule("mobility") is nullptr?
By the way, I have define mobilityType in the NED file and include IMobility.h
Upvotes: 1
Views: 2524
Reputation: 6681
The NED code you shared shows that you have a simple module that implements the IMobility interface, while the C++ code looks like something that is inside a simple module which is INSIDE a compound module that represent the network host and this compound module also contains a separate simple module called "mobility" that implements the IMobility interface. (this is how code is implemented in INET).
You should either:
getCurrentPosition
method.I assume (and recommend) that you co on the first route, so you should reaarange your NED file.
Upvotes: 2