У меня есть следующие MWE:
#include <iostream>
#include <system_error>
#include <functional>
struct A
{
A() : error() {}
void operator()(const std::error_code& ec)
{
error = ec;
std::cout << "hello world" << std::endl;
}
std::error_code error;
};
main()
{
auto handler = A();
std::error_code ec = std::error_code();
auto func = [handler](const std::error_code& ec)
{
handler(std::error_code());
};
func(ec);
}
При компиляции я получаю следующее сообщение об ошибке:
error: no match for call to '(const A) (const std::error_code&)' handler(ec);
Замена этой строки на
std::bind<void>(handler, std::error_code());
компилируется, но кажется, что оператор вызова функции структуры A никогда не вызывается.
Что здесь не так?
Спасибо за помощь!