简体   繁体   English

从 (int) 到 (short) 错误的无效缩小转换

[英]invalid narrowing conversion from (int) to (short) error

I am getting an error with both (short)m_nScreen.我收到两个(短)m_nScreen 的错误。

This is code to create a console window, and whenever I try and run it, I get errors.这是创建控制台 window 的代码,每当我尝试运行它时,都会出错。 The error I get is "invalid narrowing conversion from (int) to (short)"我得到的错误是“从(int)到(short)的无效缩小转换”

        m_rectWindow = { 0, 0, (short)m_nScreenWidth - 1, (short)m_nScreenHeight - 1 };

(short)m_nScreenHeight - 1 narrows m_nScreenHeight only to widen it again prior to the subtraction with 1, which is an int - thus an useless narrowing. (short)m_nScreenHeight - 1缩小m_nScreenHeight只是为了在减去 1 之前再次加宽它,这是一个int - 因此是一个无用的缩小。 @MM . @MM

Instead, subtract and then narrow the difference.相反,减去然后缩小差异。

// (short)m_nScreenHeight - 1
(short)(m_nScreenHeight - 1)

Same for m_nScreenWidth . m_nScreenWidth相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在{}中将'65280'从'int'转换为'short int' - Narrowing conversion of '65280' from 'int' to 'short int' inside { } 将unsigned int转换为short unsigned int - Narrowing Conversion of unsigned int to short unsigned int 在{}中将'((((int)a)+ -1)'从'int'转换为'int16_t {aka short int}' - Narrowing conversion of ‘(((int)a) + -1)’ from ‘int’ to ‘int16_t {aka short int}’ inside { } C ++-从“ int”到“ unsigned char”的无效缩小转换 - C++ - Invalid narrowing conversion from “int” to “unsigned char” 错误:从'short unsigned int *'到'short unsigned int'的无效转换| (在C ++中) - error: invalid conversion from 'short unsigned int*' to 'short unsigned int'| (in c++) 错误:{}中的'199'从'int'到'char'的转换变窄 - error: narrowing conversion of ‘199’ from ‘int’ to ‘char’ inside { } [-Wnarrowing] 为什么加short的时候会有int到short的narrowing conversion warning? (C++) - Why is there a narrowing conversion warning from int to short when adding shorts? (C++) 从“int (*)(int)”到“int”错误的无效转换? - invalid conversion from ‘int (*)(int)’ to ‘int’ error? 错误 C2397:从“int”到“unsigned int”的转换需要缩小转换 - error C2397: conversion from 'int' to 'unsigned int' requires a narrowing conversion 为什么“ unsigned int ui = {-1};”会缩小转换错误? - Why is “unsigned int ui = {-1};” a narrowing conversion error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM