gpt4 book ai didi

c++ - 迭代 std::map,做错事,提示迭代器缺少 '=' 运算符

转载 作者:太空宇宙 更新时间:2023-11-03 10:28:57 25 4
gpt4 key购买 nike

这是我的功能:

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 方法,但同样的问题仍然存在。

有什么建议吗?

最佳答案

Pathconst,因此您使用的是 .begin()const 版本。但是您正在尝试将其分配给可变迭代器。尝试将 iter 声明为 Path::const_iterator

关于c++ - 迭代 std::map,做错事,提示迭代器缺少 '=' 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com