Is casting possible in parameter expressions in OMNET++?

谁说我不能喝 提交于 2019-12-13 20:28:53

问题


I have a fairly simple bit of code in OMNET++ that takes one parameter from the user and uses it to decide several others

network ExampleNetwork
{
    parameters:
         int k;
         int variable = (k / 2);

    ...
}

This code will build correctly but when running gives the error message:

'Cannot evaluate parameter 'test'. Cannot cast 1 from type double to integer (note: no implicit conversion from double to int)'

where '1' is the value of k/2.

It seems the way to fix this would be to explicitly cast the result of the expression to int but I cannot find any documentation that states how to do this in NED files.

Does anyone know how they are meant to be written?

I believe this was working on earlier versions of OMNET++. I'm now on version 5.4 on Ubuntu.


回答1:


Sorry for answering with a simple "RTFM", but this is the most effective: https://omnetpp.org/doc/omnetpp/manual/#sec:ned-functions:category-conversion

Since OMNeT++ 5.3, double values are no longer converted to int implicitly.

Use the int function, like this: int variable = int(k / 2);



来源:https://stackoverflow.com/questions/50875724/is-casting-possible-in-parameter-expressions-in-omnet

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