我正在尝试实现一个将存储相关索引的列表。
但是,我在标题中提到的 for (index_itr = (list_size - numberOfEvents - 1)
处遇到错误。我在做什么错误,以及如何更正它?
void logPrintEntry(UINT32 index, UINT32 portID, UINT16 numberOfEvents)
{
LOG_ENTRY log;
list <UINT32> list_telnet_indices;
log = (pLOG_ENTRY) &(Data.Log.log[index]);
list <UINT32> ::iterator index_itr;
UINT16 list_size = list_telnet_indices.size();
if( list_size <= numberOfEvents )
{
// print all logs
for ( index_itr = list_telnet_indices.begin();
index_itr != list_telnet_indices.end(); ++index_itr )
{
printDataOnly(log, *index_itr, portID);
}
}
else
{
// print only the last relevant entries
for (index_itr = (list_size - numberOfEvents - 1); //error: assignment to '_List_iterator<unsigned int,unsigned int &,unsigned int *>' from 'int'
index_itr != list_telnet_indices.end(); ++index_itr)
{
printDataOnly(log, *index_itr, portID);
}
}
}
最佳答案
index_itr
是一个迭代器,list_size - numberOfEvents - 1
是一个整数。这些不兼容。
使用std::advance
设置 std::list
#include <iterator> // std::advance
index_itr = list_telnet_indices.begin();
std::advance(index_itr, list_size - numberOfEvents - 1);
for (; index_itr != list_telnet_indices.end(); ++index_itr)
{
...
}
关于c++ - 错误 : assignment to '_List_iterator<unsigned int,unsigned int &,unsigned int *>' from 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34495690/