Note that there are some explanatory texts on larger screens.

plurals
  1. POOverloading < operator c++
    primarykey
    data
    text
    <p>I'm currently trying to overload a less than operator for a class I've build that stores NFL Plays. For my class project, we're inserting data items into a BST. I've overloaded the operator in this way from within my class:</p> <pre><code>friend bool operator&lt; (const NFLData&amp; lhs, const NFLData&amp; rhs){ if((lhs.getOffenseTeam().compare(rhs.getOffenseTeam())) == 0 ){//They're equal, go left return true; } else{ return false; } } </code></pre> <p>However, the lhs and rhs parameters are underlined in red in Visual Studio 2010, and when I try to run it it, I get these errors:</p> <pre><code>c:\project 4draft\nfldata.h(105): error C2228: left of '.compare' must have class/struct/union c:\project 4draft\nfldata.h(105): error C2662: 'NFLData::getOffenseTeam' : cannot convert 'this' pointer from 'const NFLData' to 'NFLData &amp;' Conversion loses qualifiers </code></pre> <p>I removed const from both of the parameters in the function, it no longer underlines any of my code, however when I got to compile, it gives me these errors:</p> <pre><code>\bst.h(82): error C2678: binary '&lt;' : no operator found which takes a left-hand operand of type 'const NFLData' (or there is no acceptable conversion) c:\project 4draft\nfldata.h(104): could be 'bool operator &lt;(NFLData &amp;,NFLData &amp;)' [found using argument-dependent lookup] while trying to match the argument list '(const NFLData, NFLData)' c:\project 4draft\bst.h(79) : while compiling class template member function 'void BST&lt;T&gt;::insert(const T &amp;,BST&lt;T&gt;::TreeNode *&amp;) const' with [ T=NFLData ] c:\project 4draft\test.cpp(35) : see reference to class template instantiation 'BST&lt;T&gt;' being compiled with [ T=NFLData ] c:\project 4draft\bst.h(84): error C2679: binary '&lt;' : no operator found which takes a right-hand operand of type 'const NFLData' (or there is no acceptable conversion) 1&gt; c:\project 4draft\nfldata.h(104): could be 'bool operator &lt;(NFLData &amp;,NFLData &amp;)' [found using argument-dependent lookup] 1&gt; while trying to match the argument list '(NFLData, const NFLData)' </code></pre> <p>I'm trying to figure out why this isn't working, my BST is templated.</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. 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