error: passing 'const ...' as 'this' argument of ... discards qualifiers

Hi everybody.
I hope you can help me, because I have never handled before such a kind of error before. Here is parts of my sourcecode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class QNode
{
QNode()
      {
      	assignments = NULL;
      }

   	/* Destructor */
      ~QNode()
      {
      	if(assignments != NULL)
         	delete [] assignments;

         assignments = NULL;
      }

      /* Constructor */
      QNode (int * as)
      {
   		assignments = new int[NUMBER_OBJECTS];
         for(int i=0; i<NUMBER_OBJECTS; i++)
         {
         	assignments[i] = as[i];
            if(assignments[i] >= NUMBER_OBJECTS)
            {
            	printf("\n\nInvalid Data in Copy Constructor");
               exit(1);
            }
         }
         calculateValue();
      }

...

 /* Operator '<' Used by std::sort */
      bool operator < (const QNode & right) const
      {
      	int av = this->getValue();  // ERROR APPEARS HERE!!!
	int bv = right.getValue();
	return av < bv;
      } 

};



by compiling the code in this part of the implementation the following error appears:
"error: passing ‘const QNode’ as ‘this’ argument of ‘int QNode::getValue()’ discards qualifiers"

Do you have any experience or idea how to handle this error?

Thanks everybody in advance.
Last edited on
closed account (DSLq5Di1)
You'll need a const suffix for QNode::getValue() too, else your less-than function cannot guarantee this object is not modified.
Topic archived. No new replies allowed.