Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access non-const member functions of objects in C++ std::set
    primarykey
    data
    text
    <p>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:</p> <blockquote> <p>“In function 'void messageTimeOut(threadParameters*)': main.cpp:74:33: error: passing 'const Message' as 'this' argument of 'void Message::setTimedOut(bool)' discards qualifiers [-fpermissive].”</p> </blockquote> <p>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</p> <p>Part of my code:</p> <pre><code> [ . . . ] void messageTimeOut( threadParameters* params ) { set&lt;Message&gt;::iterator it = params-&gt;messages-&gt;begin(); [ . . . ] for ( ; it != params-&gt;messages-&gt;end(); ++it ) { if ( (it-&gt;createdTime() + RESPONSE_WAIT) &lt; GetTickCount() ) { it-&gt;setTimedOut(true); // error } } ReleaseMutex(sentQueueMutex); } [ . . . ] int main() { threadParameters rmparameters; set&lt;Message&gt; sentMessages; [ . . . ] rmparameters.logFile = &amp;logFile; rmparameters.socket = socketDesciptor; rmparameters.messages = &amp;sentMessages; [ . . . ] messageTimeOut( rmparameters ); [ . . . ] return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload