解决警告——有符号 无符号不匹配

转:https://blog.csdn.net/lxw907304340/article/details/47399207

解决警告——warning C4018: “<”: 有符号/无符号不匹配

今天遇到这个问题,虽然不影响程序运行,但作为完美主义者,有警告总感觉不舒服,所以就查了一下解决方法:

出错代码: for(int j=0;j<detector.size();j++)

出错原因分析: detector 是一个Vector容器 ,detecot.size() 在容器说明中 被定义为: unsigned int 类型, 而j是int 类型 所以会出现: 有符号/无符号不匹配警告

错误改正: 定义j为unsigned类型后就可以了

即: for(unsigned int j=0;j<detector.size();j++)
或者: for(size_t int j=0;j<detector.size();j++)

猜你喜欢

转载自blog.csdn.net/reasonyuanrobot/article/details/84072638
今日推荐