Omnet++ OMNET++;如何访问另一个类中的函数或变量
我使用一个自定义函数修改了inet NodeStatus.cc,该函数返回变量值,如下所示:Omnet++ OMNET++;如何访问另一个类中的函数或变量,omnet++,inet,Omnet++,Inet,我使用一个自定义函数修改了inet NodeStatus.cc,该函数返回变量值,如下所示: int NodeStatus::getValueA() { return ValueA; } 然后,我创建了另一个名为simpleNodeB.cc的简单模块,我想从NodeStatus.cc检索ValueA。我在simpleNodeB.cc中尝试了以下代码,但没有成功: if(getParentModule()->getSubModule(NodeStatus).getValueA()=
int NodeStatus::getValueA()
{
return ValueA;
}
然后,我创建了另一个名为simpleNodeB.cc的简单模块,我想从NodeStatus.cc检索ValueA。我在simpleNodeB.cc中尝试了以下代码,但没有成功:
if(getParentModule()->getSubModule(NodeStatus).getValueA()==test1)
bubble("Value is the same");
我收到的错误消息->错误:在“')标记之前应该有主表达式。我不确定调用getValueA()函数的方法是否正确。请开导我。非常感谢。您的代码中有许多错误
getSubmodule
需要,而不是类的名称。查看您的NED
文件并检查此模块的实际名称getSubmodule
返回指向cModule
对象的指针。它必须手动转换到另一个类中NED
中的NodeStatus
模块名为fooStatus
正确的代码如下所示:
cModule *mod = getParentModule()->getSubmodule("fooStatus");
NodeStatus *status = check_and_cast<NodeStatus*>(mod);
if(status->getValueA() == test1)
bubble("Value is the same");
cModule*mod=getParentModule()->getSubmodule(“fooStatus”);
NodeStatus*状态=检查和铸造(mod);
如果(状态->getValueA()==test1)
泡沫(“价值相同”);
参考文献: