我有以下 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 的函数调用运算符永远不会被调用。
这里有什么问题?
谢谢您的帮助!