user2771016
user2771016

Reputation: 1

C++ Argument Error

I have a function in which

bool(*p)(const vector<int>&, int)

is one of the arguments. I know it's being used to call one of two other functions, but I can't seem to figure out how to actually call it (getting a no matching function for call error). I currently have

myFunct(i, j, myFunct2(i, 0);

Any help is appreciated.

Upvotes: 0

Views: 105

Answers (2)

Szpadel
Szpadel

Reputation: 61

this argument is an pointer to function. if should just use function name as argument

example:

bool myFunct2(const vector<int>& a, int b) { ... };
myFunct(i, j, &myFunct2); // you passing myFunct2 to your functuin

Upvotes: 0

user2357112
user2357112

Reputation: 280291

That weird jumble of stuff declares an argument named p that needs to be a pointer to a function. The function p points to needs to take two arguments, the first being a const reference to a vector of ints and the second being an int. The function p points to needs to return a bool. If you have a function of the following form somewhere:

bool foo(const vector<int>& a, int b);

Then you can pass &foo as p. You should not provide a vector<int> or an int; the function you're passing p to will take care of that.

Upvotes: 2

Related Questions