c++ - 警告 C4018 : '>' : signed/unsigned mismatch

标签 c++ compiler-errors

很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .




8年前关闭。




任何人都可以帮我解决签名的未签名不匹配问题吗?这是关于如果 my_size

void set::add(SET_ITEM_TYPE newItem)
  // post: If newItem is not in this set, newItem is added
  //       and the size of the set increased by +1.

 {
     if (positionOf(newItem) == -1 )
  {

  if(my_size >= my_item.capacity())
  {
    my_capacity = 2 * my_item.capacity();
    my_item.resize( my_capacity );
  }
    my_item[my_size] = newItem;

     my_size++;
  }
}

最佳答案

假设 my_size定义为 int ,您可以通过将其类型更改为 unsigned int 来解决此问题.大小不能为负数;为什么要签名?

(std::vector::size 等返回无符号类型是有原因的)

关于c++ - 警告 C4018 : '>' : signed/unsigned mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17203859/

相关文章:

c++ - 使用 Boost 编译的 Visual Studio

C++ Worker threads with Builder (Borland Libraries)

c++ - 使用模板参数包代替宏

visual-studio - 为什么Visual Studio错误列表在102个错误处停止?

c - 对 `FindTheVolumeAndSurfaceArea' 的 undefined reference

c++ - C 中的信赖域反射算法库

C++ STL 的 copy() 异常安全

vim - Vim 自动转到下一个编译错误

c++ - 重载调用不明确 : one-pair inline map as constructor argument

Ant 中的 Java 编译错误 : using class literals in annotations