Will Nasby
Will Nasby

Reputation: 1148

Argument of type bool does not match

I'm trying to sort a vector of nodes which data contains an object I made. The thing I'm comparing is a value of that object (relevance). I get an error:

BST.h:148: error: argument of type âbool (BST<Play>::)(BST<Play>::node*, BST<Play>::node*)â does not match âbool (BST<Play>::*)(BST<Play>::node*, BST<Play>::node*)â

I've never seen an error like this, it's called on the line I call my sort.

#ifndef BST_H
#define BST_H
#include "Play.h"
#include <algorithm> 
#include <vector>
#include <iostream>

template<typename T>
class BST
{
    public:
        struct node{
            T data;
            node *left;
            node *right;
            node *parent;

            node(const T & theData, node *lt, node *rt, node *pt):
                data(theData), left(lt), right(rt), parent(pt) {}
        };
        std::vector<node*> tempVec;
        bool sorterFunc(node* x, node* y) { 
            return (y->data.getRelevance() < x->data.getRelevance());
        }
        void list(std::string offense, std::string defense, int downforplay, int yardstogo, int yardline, int minutes, node* &t, int level){
            tempVec.clear();
            float relevance;
            if(t==NULL){
                return;
            }
            if(level ==1){
                tempCount--;
                if(offense==t->data.getoTeam()){
                    if(downforplay==t->data.getDown()){
                        int yardabove = yardstogo+1;
                        int yardbelow = yardstogo-1;
                        if(yardstogo==t->data.getYard() || yardbelow==t->data.getYard() || yardabove==t->data.getYard()){
                            if(yardline >= t->data.getStartLoc() - percentback(yardline) && yardline <= (t->data.getStartLoc() + percentback(yardline))){
                                relevance= -((float)abs(minutes - t->data.getMinutes())*(float(5/3)) + (float)abs(yardstogo - t->data.getYard()) + (float)abs(yardline - t->data.getStartLoc()));
                                if(defense == t->data.getdTeam())
                                    relevance += 100;
                                t->data.setRelevance(relevance);
                                tempVec.push_back(t);
                            }
                        }
                    }
                }
            }
            else{
                list(offense, defense, downforplay, yardstogo, yardline, minutes, t->left, level-1);
                list(offense, defense, downforplay, yardstogo, yardline, minutes, t->left, level-1);
            }
        }
        void listFunc(std::string offense, std::string defense, int downforplay, int yardstogo, int yardline, int n, int minutes){
            tempCount = treeCount;
            for(int i=1; tempCount>0; i++)
                list(offense, defense, downforplay, yardstogo, yardline, minutes, root, i);
            std::sort(tempVec.begin(), tempVec.end(), sorterFunc);
            for(int i=0; i<n; i++)
                std::cout << tempVec[i]->data.getwholePlay() << std::endl << tempVec[i]->data.getRelevance();
        }
}

Upvotes: 1

Views: 956

Answers (1)

Zeta
Zeta

Reputation: 105876

sorterFunc is a member function. As such, it can only work on instances. However, you try to use it as a function for comparing node*:

std::sort(tempVec.begin(), tempVec.end(), sorterFunc);

Now std::sort will call sorterFunc at some place, but this would fail, since there is no instance to work with:

       sorterFunc( someNodePointer, someOtherNodePointer);
// ^^. missing instance

You don't want sorterFunc to work on any instance. Make it static instead:

static bool sorterFunc(node* x, node* y) { 
    return (y->data.getRelevance() < x->data.getRelevance());
}

Upvotes: 4

Related Questions