2

I have the following definitions and prototypes (which are member functions of a class) with which I basically try to use function pointers to pass a different type of strategy to the divideQuery method:

typedef vector<ConstraintManager> (*strategyType1)(const Query&);
typedef vector<ConstraintManager> (*strategyType2)(const Query&, int);

vector<ConstraintManager> divideQuery (strategyType1 s, const Query& query);
vector<ConstraintManager> divideQuery (strategyType2 s, const Query& query, int parts);

vector<ConstraintManager> divideByHalf(const Query& query);
vector<ConstraintManager> divideRandom(const Query& query);
vector<ConstraintManager> divideByN(const Query& query, int n);

However when I try to call (query parameter is passed from the wrapping function):

vector<ConstraintManager> result =  divideQuery(divideRandom, query);

It fails with the error message:

DividingSolver.cpp:200:70: error: no matching function for call to ‘DividingSolver::divideQuery(<unresolved overloaded function type>, const klee::Query&)’
DividingSolver.cpp:82:27: note: candidates are: std::vector<klee::ConstraintManager>   DividingSolver::divideQuery(std::vector<klee::ConstraintManager> (*)(const klee::Query&),  const klee::Query&)
DividingSolver.cpp:87:27: note: std::vector<klee::ConstraintManager>     DividingSolver::divideQuery(std::vector<klee::ConstraintManager> (*)(const klee::Query&, int), const klee::Query&, int)

As far as I read from the web it seems like an overloading error (or maybe something else) but in any case I am not quite sure what exactly is wrong. Any hints/explanations is appreciated.

Cheers

7
  • 1
    The error you're getting seems like the one you'd get if there were multiple divideRandom functions (that is, the name divideRandom was overloaded). Are you sure that you only have one implementation? Commented Jul 9, 2012 at 21:43
  • 1
    I added #include <vector> using std::vector; struct Query {} query; struct ConstraintManager {}; and it compiled for me. (gcc 4.7.?) Commented Jul 9, 2012 at 21:46
  • 2
    Are the divideXXX member functions of a class? Commented Jul 9, 2012 at 21:47
  • This isn't by any chance an issue with something not being #included or using'd? It says "unresolved overloaded function type", which implies it doesn't recognize your typedef as a function pointer, or rather that it does, but doesn't understand the signature. Commented Jul 9, 2012 at 21:47
  • @dribeas: Based on the error message, yes they are. Commented Jul 9, 2012 at 21:50

2 Answers 2

5

The problem is that a non-static member function does not have the same signature as a free function. In particular it has a hidden this pointer. Now what you have is a call to divideQuery where the first argument is a pointer to member function, but there is no overload that takes pointer to member function, so the compiler bails out with an error message.

If the functions do not use the state from the class, you can make them static, that will remove the implicit this and it should work. Another option is actually using pointers to member in the divideQuery interface. The third option would be using a higher level construct, like std::function<> (or boost::function<>) for the function argument, and then using std::bind (boost::bind) to bind the this argument.

Sign up to request clarification or add additional context in comments.

1 Comment

@CharlesBailey It's a member function and the question is edited accordingly. Thanks.
4

Make divideRandom static, then it will be compatible with a normal function pointer.

1 Comment

@CharlesBailey: the question is missing the important point that these are all member functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.