开发者

Have narrowing conversion error in C++ arm from Android NDK

I have narrowing conversion error in C++ arm from Android NDK.

Have a following code:

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 struct:

typedef struct tagRect16 {
   开发者_运维知识库 int16_t left, top, right, bottom;
} Rect16;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜