I'm trying to pass a list into a function to edit it but when I
compile using g++ I continue to get the following error:
maintainNeighbo rs.cpp:104: error: invalid initialization of non-const
reference of type 'std::list<Host ID, std::allocator< HostID&' from a
temporary of type 'std::list<Host ID, std::allocator< HostID*'
helpers.cpp:99: error: in passing argument 1 of `void
CheckIfNeighbor sHaveSentHello( std::list<HostI D, std::allocator< HostID>
>&)'The function is shown below:
void CheckIfNeighbor sHaveSentHello( std::list<struc t HostID>
&Neighbors)
{
std::list<struc t HostID>::iterat or it;
std::list<struc t HostID>::iterat or LastIt;
struct timeb TimeBuffer;
ftime( &TimeBuffer );
it=Neighbors.be gin();
while (it!=Neighbors. end())
{
int Del=0;
if (TimeBuffer.tim e - it->LastHelloRec 40)
Del=1;
LastIt = it;
++it;
if (Del==1)
Neighbors.erase (LastIt);
}
}
And the objects contained in the list are shown below, along with how
it is defined and the function call itself:
struct HostID {
char IP[16];
int Port;
int LastHelloRec;
int LastHelloSent;
};
std::list<struc t HostIDActiveNei ghbors;
CheckIfNeighbor sHaveSentHello( &ActiveNeighbor s);
My guess is that it has something to do with the iterator, but I've
been stuck on this for a while now and I figure a more experienced
person could guide me in the right direction. Thanks in advance for
any help!