title: Overloading a bool operator with a member function
body: <p>I have a class like this:</p>
  
  <pre><code>    class AI
      {
      private:
          struct Comparator
          {
              bool operator()(const Town* lfs, const Town* rhs)
              {
                  return GetHeuristicCost(lfs) &gt; GetHeuristicCost(rhs);
              }
          };
  int GetHeuristicCost(const Town* town);
      // constructor and variables
      };
  </code></pre>
  
  <p><code>GetHeuristicCost</code> returns the heuristic from the town parameter to the <code>exit</code> of the path.</p>
  
  <p>What I am trying to do is overload the bool operator for a priority queue but it gives me the error </p>
  
  <pre><code>a nonstatic member reference must be relative to a specific object
  </code></pre>
  
  <p>I know why it is giving me this error but what I don't know is how to use a nonstatic function inside the <code>Comparator</code> struct.</p>
  
  <ol>
  <li><code>GetHeuristicCost</code> must be nonstatic</li>
  <li>I tried moving <code>GetHeuristicCost</code> inside the <code>Town</code> class to no avail</li>
  <li><p>I need to overload the operator with a struct because I need to use two different bool overloadings on the <code>()</code> for two different circumstances but with the same parameters (two Towns). In other words I need the struct so I can't do this:</p>
  
  <p>bool operator()(const Town* lfs, const Town* rhs)
  {
  return GetHeuristicCost(lfs) > GetHeuristicCost(rhs);
  }</p></li>
  </ol>
  
  <p>Basically I plan on having two structs like this:</p>
  
  <pre><code>struct Comparator1
  {
      bool operator()(const Town* lfs, const Town* rhs)
      {
          return GetHeuristicCost(lfs) &gt; GetHeuristicCost(rhs);
      }
  };
  
  struct Comparator2
  {
      bool operator()(const Town* lfs, const Town* rhs)
      {
          return GetHeuristicCost(lfs) + GetTotalCost (lfs, rhs) &gt; GetHeuristicCost(rhs) + GetTotalCost (lfs, rhs);
      }
  };
  </code></pre>