Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your member function needs to be <code>const</code>-qualified:</p> <pre><code>bool operator&lt;(const Node&lt;T&gt;&amp; rhs) const{ </code></pre> <h2>EDIT</h2> <p>Per request, here is a bit more how I knew that you needed to make the member function <code>const</code>.</p> <p>Divining the hidden meanings in stdlib-related compiler errors is something of an art, and something that you get better at with practice. Stdlib-related errors will often emit a whole series of compiler errors. Usually the most useful of these errors is the last one, because that one is generated from the context of the code you actually wrote, rather than coming from the bowels of the library code.</p> <p>In this case, the last compiler error was:</p> <blockquote> <p>graphBuilder.cpp:10:17: instantiated from here /usr/lib/gcc/i486-slackware-linux/4.5.2/../../../../include/c++/4.5.2/bits/stl_algo.h:2211:4: error: <strong>passing 'const Node</strong> >' <strong>as 'this'</strong> argument of 'bool Node::operator&lt;(const Node&amp;) [with T = std::basic_string]' <strong>discards qualifiers</strong></p> </blockquote> <p>I've highlighted the illuminating bits. This tells me that in OP's actual code, because of how the code is constructed (maybe the <code>sort</code> call is itself in a <code>const</code> member function? who knows...) the <code>this</code> pointer must be <code>const</code>, but as we can see from the posted declaration of <code>operator&lt;</code>, the method is not <code>const</code>. The "qualifiers" referred to in the compiler errors are what the Standard calls "cv-qualifiers". "cv" stands for "const/volatile." </p> <p>When the compiler says "Passing <code>const X</code> as <code>this</code> to <code>Node::operator&lt;</code> discards qualifiers" what it's really trying to say is:</p> <p>"You said <code>X</code> was const but then you tried to call a non-const member function through <code>const X</code>. In order for me to make this call, I would have to <em>discard</em> the const qualifier on <code>X</code>. I'm not allowed to do that, so you have to fix your code."</p> <p>The qualifiers being "discarded" here are the qualifiers on the method itself. In other words, <code>operator&lt;</code> must be a const member function, but it's not.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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