Debug Assertion失败map / set iterator not dereferencable

时间:2015-03-20 03:39:36

标签: c++ dictionary

我有我的地图 std::map<const char*, int> uniforms; 当我尝试使用时找到数据 uniforms.find(name)->second 我收到了错误说明。 我已经检查了存储在调试模式下的数据,并且正如我所期望的那样正确,我可以使用find函数访问大部分数据,但是当我尝试访问directionalLight.base.color时,我收到错误。就像我说他们拼写正确,并在调试模式,但我得到错误。它是字符串中的点吗?

1 个答案:

答案 0 :(得分:1)

您可能正在超越地图的末尾,因此在取消引用之前,您应检查其是否有效

auto it = uniforms.find(name) ; // or std::map<const char*, int>::iterator it ;

if ( it != uniforms.end() )
{
   // Now use  it->second 
}