问题描述
我在OMNET ++中有一段相当简单的代码,它从用户那里获取一个参数,并用它来决定其他几个参数
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:
其中"1"是k/2的值.
where '1' is the value of k/2.
解决此问题的方法似乎是将表达式的结果显式转换为int,但是我找不到在NED文件中说明如何执行此操作的任何文档.
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.
有人知道怎么写吗?
我认为这适用于OMNET ++的早期版本.我现在在Ubuntu上使用5.4版.
I believe this was working on earlier versions of OMNET++. I'm now on version 5.4 on Ubuntu.
推荐答案
很抱歉使用简单的"RTFM"回答,但这是最有效的方法: https://omnetpp.org/doc/omnetpp/manual/#sec:ned-functions:category-conversion
Sorry for answering with a simple "RTFM", but this is the most effective: https://omnetpp.org/doc/omnetpp/manual/#sec:ned-functions:category-conversion
自OMNeT ++ 5.3起,double
值不再隐式转换为int
.
Since OMNeT++ 5.3, double
values are no longer converted to int
implicitly.
使用int
函数,如下所示:int variable = int(k / 2)
;
Use the int
function, like this: int variable = int(k / 2)
;
这篇关于可以在OMNET ++中的参数表达式中进行强制转换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!