简体   繁体   中英

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM