C++ vector.size() warning C4018

梦想的初衷 提交于 2020-03-08 07:07:30

node_vec为vector
若写为

  for ( int j = 1; j< node_vec.size(); j++)
  {
   node_vec[j - 1]->next = node_vec[j];
  }

也会运行得到正确的结果,但会有warning:
warning C4018: “<”: 有符号/
这是由于C++中vector的size()为unsigned int类型。
应该写为:

  for (unsigned int j = 1; j< node_vec.size(); j++)
  {
   node_vec[j - 1]->next = node_vec[j];
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!