1

The following code does not compile:

auto greater_than = [](const int a, const int b) { return a > b; };
auto is_adult = bind(&greater_than, placeholders::_1, 17);
cout << "Age 19 is adult = " << is_adult(19) << endl;

The is_adult call is giving a vague error:

error: no matching function for call to object of type 'std::_Bind<(lambda at main.cpp:62:23) *(std::_Placeholder<1>, int)>'

However, if I move the greater_than to be a global function then it works.

Why is that?

2

1 Answer 1

5

Remove the &. Even though pointers-to-functions are callable, pointers to objects with overloaded operator() are not.

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

Comments

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.