Robbie Cooper
Robbie Cooper

Reputation: 483

No matching function

I'm using a function from a header file that's pre-defined for the exercise I'm doing. In main I've got;

defineClickListener(clickAction, graph);

clickAction is a function I've made and has a prototype above main and graph is an instance of a pathfindergraph class. In pathfindergraphics header, which is included, it says;

/**
 * Function: defineClickListener
 * Usage: defineClickListener(clickFn);
 *        defineClickListener(clickFn, data);
 * ------------------------------------------
 * Designates a function that will be called whenever the user
 * clicks the mouse in the graphics window.  If a click listener
 * has been specified by the program, the event loop will invoke
 *
 *       clickFn(pt)
 *
 * or
 *
 *       clickFn(pt, data)
 *
 * depending on whether the data parameter is supplied.  In either
 * case, pt is the GPoint at which the click occurred and data
 * is a parameter of any type appropriate to the application.  The
 * data parameter is passed by reference, so that the click function
 * can modify the program state.
 */
void defineClickListener(void (*actionFn)(const GPoint& pt));

template <typename ClientType>
void defineClickListener(void (*actionFn)(const GPoint& pt, ClientType & data), ClientType & data);

As far as I can see I'm using the defineClickListener correctly, but I'm getting an error that says "no matching function for call to 'defineClickListener'". Not sure what I'm doing wrong- any ideas?

Upvotes: 0

Views: 102

Answers (1)

AnT stands with Russia
AnT stands with Russia

Reputation: 320531

It means that the arguments you supplied cannot be matched to the parameters of the template function you are trying to call. There could be many reasons for this. Error message generated by the compiler typically includes additional information.

I would make a semi-wild guess that your clickAction is a non-static member function.

EDIT: According to the additional information you supplied your clickAction is declared as

static void clickAction(PathfinderGraph *&graph)

This is completely unacceptable. Firstly, the handler function has to have two paramaters, the first being const GPoint&

static void clickAction(const GPoint& pt, PathfinderGraph *&graph)

Secondly, according to the template declaration the type of the second parameter of the handler function must match the type of the last parameter of defineClickListener, i.e. both must be references to the same type. What is graph in your call to defineClickListener. If graph is a pointer to PathfinderGraph, then you should indeed use the above declaration.

But if graph is not a pointer (a reference to graph object or graph object itself), then it should be

static void clickAction(const GPoint& pt, PathfinderGraph &graph)

Upvotes: 1

Related Questions