[英]std::swap error assignment of read-only reference
void sort_this(std::map<BITMAP*,MAPS>::iterator start,std::map<BITMAP*,MAPS>::iterator endd)
{
for(auto itt=start;itt!=endd;itt++)
{
for(auto it=start;it!=endd;it++)
{
if(itt->second.type > it->second.type)
{
std::swap(*it,*itt);
}
}
}
}
我需要交换*it
和*itt
,它给出了这个错误。
files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\move.h|177|
error: assignment of read-only reference '__a'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\move.h|178|
error: assignment of read-only reference '__b'|
编辑:此功能的目的是排列地图元素。 根据second.type
std::map
迭代器对于键始终是恒定的(考虑一下,如果更改键值,则潜在的树有被破坏的危险!),但是可以交换这些值:
std::swap(it->second, itt->second);
免责声明:这可能是您想要的,也可能不是,因为我不知道交换的目的是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.