Message is a class I made. I have a set of them in the main function that I pass to messageTimeOut (and some other functions). In messageTimeOut using an itorator I am looping through them and accessing different member functions. However, I can only access const member functions of the Message pointed to by the iterator. If I try to access non const member functions I get the error:
“In function 'void messageTimeOut(threadParameters*)': main.cpp:74:33: error: passing 'const Message' as 'this' argument of 'void Message::setTimedOut(bool)' discards qualifiers [-fpermissive].”
It makes sense that I cannot access a non-const member function of a const Message object, but how do I go about making this a non const Message object so I can access non const member functions and change the Message? Thanks
Part of my code:
[ . . . ]
void messageTimeOut( threadParameters* params )
{
set<Message>::iterator it = params->messages->begin();
[ . . . ]
for ( ; it != params->messages->end(); ++it )
{
if ( (it->createdTime() + RESPONSE_WAIT) < GetTickCount() )
{
it->setTimedOut(true); // error
}
}
ReleaseMutex(sentQueueMutex);
}
[ . . . ]
int main()
{
threadParameters rmparameters;
set<Message> sentMessages;
[ . . . ]
rmparameters.logFile = &logFile;
rmparameters.socket = socketDesciptor;
rmparameters.messages = &sentMessages;
[ . . . ]
messageTimeOut( rmparameters );
[ . . . ]
return 0;
}