如下:
vector<int> _vecTest;
_vecTest.push_back(10);
_vecTest.push_back(11);
int aaa = -1;
bool _bMaxMin = (aaa >= _vecTest.size());
如上, _bMaxMin 值为 true;
Why????????
vector<int> _vecTest;
_vecTest.push_back(10);
_vecTest.push_back(11);
int aaa = -1;
bool _bMaxMin = (aaa >= _vecTest.size());
如上, _bMaxMin 值为 true;
Why????????
解决方案
10
_vecTest.size() 是无符号整数值,你int -1首先会转换成 无符号数,然后再比较
-1 转为无符号数会变得很大,你要这样子比较就得相似
bool _bMaxMin = (aaa >= (int)_vecTest.size()); //强制转换下
-1 转为无符号数会变得很大,你要这样子比较就得相似
bool _bMaxMin = (aaa >= (int)_vecTest.size()); //强制转换下
20
size_type size() const;
Member type size_type is an unsigned integral type.
http://www.cplusplus.com/reference/vector/vector/size/
所以需要强转成int再比较
Member type size_type is an unsigned integral type.
http://www.cplusplus.com/reference/vector/vector/size/
所以需要强转成int再比较
bool _bMaxMin = (aaa >= (int)_vecTest.size());