简体   繁体   中英

how to access the different nodes of my simulation in OMNet++?

I want to get nodes of the network simulation and I found this piece of code:

int nodeID = getId();
cModule* parent = getParentModule();
cModule* module;
this->num_nodes = parent->par("numHosts");
for(int i = 1; i <= simulation.getLastModuleId(); i++)
    {
        module = simulation.getModule(i);
        if (module->getId() != nodeID)
        {
             // Some code
        }
    }

But when I try to compile it I have the error:

use of an undeclared identifier for "simulation".

Add the following line at the beginning of your code:

auto simulation = getSimulation(); 

and for simulation change dot operators into arrows, ie:

simulation->getLastModuleId() 
simulation->getModule(i)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM