在来自 Android NDK 的 C++ arm 中出现缩小转换错误 [英] Have narrowing conversion error in C++ arm from Android NDK
本文介绍了在来自 Android NDK 的 C++ arm 中出现缩小转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在来自 Android NDK 的 C++ arm 中出现缩小转换错误.
I have narrowing conversion error in C++ arm from Android NDK.
有以下代码:
int16_t ax = li.A.x, ay = li.A.y;
int16_t bx = li.B.x, by = li.B.y;
Rect16 rcA = { ax - 8, ay - 8, ax + 8, ay + 8 };
Rect16 rcB = { bx - 8, by - 8, bx + 8, by + 8 };
尝试编译时出现此错误:
And get this error, when try to compile:
error: narrowing conversion of '(((int)ay) + -0x00000000000000008)' from 'int' to 'int16_t' inside { }
Rect16 结构体:
Rect16 struct:
typedef struct tagRect16 {
int16_t left, top, right, bottom;
} Rect16;
推荐答案
你的问题源于在表达式 ay - 8
中编译器说你正在调用 int operator-(int, int)
.您需要使用 这个问题.
Your problem stems from the fact that in the expression ay - 8
the compiler says you are calling int operator-(int, int)
. You need to tell the compiler that 8 is a short, using a method like in this question.
这篇关于在来自 Android NDK 的 C++ arm 中出现缩小转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文