这是我的功能:
friend std::ostream& operator<< (std::ostream& stream, const Path& path) {
std::map<double, glm::vec3>::iterator iter;
for (iter = path.points.begin(); iter != path.points.end(); iter++){
stream << "test" << "\n";
}
}
这是我的错误:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>' (or there is no acceptable conversion) c:\users\adam\skydrive\documents\proj\ray\ray\path.h 22 1 ray
我以前从来没有遇到过这种问题。老实说,我不知道从哪里开始。我尝试了几种获取迭代器的方法,包括 typedef 方法,但同样的问题仍然存在。
有什么建议吗?
最佳答案
Path
是 const
,因此您使用的是 .begin()
的 const
版本。但是您正在尝试将其分配给可变迭代器。尝试将 iter 声明为 Path::const_iterator
。
关于c++ - 迭代 std::map,做错事,提示迭代器缺少 '=' 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236317/