gpt4 book ai didi

c++ - 迭代我的对象停止工作

转载 作者:行者123 更新时间:2023-11-28 03:42:50 24 4
gpt4 key购买 nike

由于某些原因这段代码抛出一个错误

// map<int, AnItem> roomlist;
// map<string, long> rinventory

map<int, AnItem>::iterator it;

for ( it = roomlist[roomno].rinventory.beg/in(); it != roomlist[roomno].rinventory.end(); it++ ) {

if( (*it).second.name == "Stock" )
tmpitem.append( strmug );
}

if 语句抛出错误。它真的没有那么复杂,我想我可以处理这个。所以... roomlist 是一张 map ,roomno 是一个整数,rinventory 是一张 map

class AnThing   {

public:
AnThing(); // constructor
string name; // name reference
int gtid; // Thing ID
string lcname; // name in lowercase
string m_name;
};

class AnItem : public AnThing {

public:

ItemType m_type;
int imin;
int imax;
int ispeed;
long unsigned iprice;
unsigned int ecoin;
GAttributes m_attributes;

AnItem(); //Constructs an item with "invalid" values

int& Min(); // Returns the min attribute
int& Max(); // Returns the max attribute
int& Speed(); // Returns the speed attribute

};

提前致谢!我将在下面附加我得到的错误(其中有两个)

c:\ucdhb2\gaia\logonserver\v6\gaiaserver.cpp(812) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree<_Traits>::iterator' (or there is no acceptable conversion) 1> with 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\xtree(498): could be 'std::_Tree<_Traits>::iterator &std::_Tree<_Traits>::iterator::operator =(const std::_Tree<_Traits>::iterator &)' 1> with 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> while trying to match the argument list '(std::_Tree<_Traits>::iterator, std::_Tree<_Traits>::iterator)' 1> with 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> and 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1>c:\ucdhb2\gaia\logonserver\v6\gaiaserver.cpp(812) : error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_Tree<_Traits>::iterator' (or there is no acceptable conversion) 1> with 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> c:\program files\microsoft sdks\windows\v6.0a\include\guiddef.h(197): could be 'int operator !=(const GUID &,const GUID &)' 1> c:\program files\microsoft visual studio 9.0\vc\include\xtree(314): or 'bool std::_Tree<_Traits>::const_iterator::operator !=(const std::_Tree<_Traits>::const_iterator &) const' 1> with 1>
[ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> while trying to match the argument list '(std::_Tree<_Traits>::iterator, std::_Tree<_Traits>::iterator)' 1> with 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ] 1> and 1> [ 1>
_Traits=std::_Tmap_traits,std::allocator>,false> 1> ]

最佳答案

你的迭代器

map<int, AnItem>::iterator it;

需要类型

map<string, long>::iterator it;

根据您的评论(即您正在遍历 rinventory,而不是 roomlist)。

关于c++ - 迭代我的对象停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8573608/

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