从'int'转换为'short unsigned int'可能会改变其值

时间:2016-07-27 14:08:48

标签: c++ gcc-warning

我没有提出以下警告的解决方案:

main.cpp: In member function 'void MyClass::increase()':
main.cpp:350: warning: conversion to 'short unsigned int' from 'int' may alter its value

main.cpp中:

class MyClass {
public:
   MyClass() : myShort(0) { }
   void increase() { myShort *= 60; } // Line 350

private:
   unsigned short myShort;
};

int main(int argc, char** argv)
{
   MyClass myObj;
   myObj.increase();
}

0 个答案:

没有答案