可以在OMNET ++中的参数表达式中进行强制转换吗? [英] Is casting possible in parameter expressions in OMNET++?

查看:93
本文介绍了可以在OMNET ++中的参数表达式中进行强制转换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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:

'无法评估参数'test'.无法将1从double类型转换为 整数(注意:没有从double到int的隐式转换)'

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

其中"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"回答,但这是最有效的方法:

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 ++中的参数表达式中进行强制转换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆