将int16转换为cpp中的double

时间:2016-03-22 17:33:33

标签: c++ qt casting integer double

我试图将qint16int16)与double投放到mydouble = (double) myInt16;并获得

error: invalid cast from type 'qint16* {aka short int*}' to type 'double'

如何将int16转换为double

2 个答案:

答案 0 :(得分:2)

根据您显示的代码,您没有int。你有一个指向int的指针。取消引用它,如下:

// Assume src points to a short int
double mydbl = *src;

从整数到双精度的转换将是自动的,但您必须取消引用指针。

答案 1 :(得分:2)

从错误中,myInt16是指向short int的指针。所以只需使用:

double mydouble = *myInt16;

short int会自动提升为双倍。

相关问题