【问题标题】:typedef map, debug assertion on for loop, map/set incompatibletypedef 映射,for 循环上的调试断言,映射/设置不兼容
【发布时间】:2013-11-05 09:20:29
【问题描述】:

所以当我遇到调试断言时,我正在编码。 现在我很感兴趣为什么这段代码不起作用:

for(Model::MeshMap::iterator it = obj1->GetMeshes().begin(); it != obj1->GetMeshes().end(); it++)

这段代码可以做到:

Model::MeshMap obj1meshes = obj1->GetMeshes();
for(Model::MeshMap::iterator it = obj1meshes.begin(); it != obj1meshes.end(); it++)

在模型类中我有这个:

typedef std::map<std::string, Mesh*> MeshMap;

【问题讨论】:

  • 什么返回GetMeshes?复制还是参考?
  • @ForEveR:这里的美妙之处在于,无论答案如何,这意味着两个版本都被严重破坏了......
  • 调试断言说什么?它真的发生在 for 行还是循环中的某处?
  • @ForEveR:GetMeshes 返回我想使用的地图。 MeshMap GetMeshes() {return m_Meshes;} m_Meshes = Meshmap 类型。

标签: c++ debugging iterator stdmap assertion


【解决方案1】:

看起来GetMeshes 返回副本,您正试图将一个容器的iterator 与另一个容器的iterator 进行比较。这种比较对于 MSVC 中的检查迭代器是无效的。而且,感谢@Mike Seymour,根据 C++ 标准,这种比较是无效的。

【讨论】:

  • 更重要的是,根据 C++ 标准,这样的比较是无效的。
  • 啊哈,所以这会创建网格图的副本?这是通过使用参考解决的。谢谢!
猜你喜欢
  • 2021-07-28
  • 1970-01-01
  • 2012-03-31
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多