【发布时间】:2019-07-10 11:04:10
【问题描述】:
我尝试了以下方法:
typedef std::function<void(int)> callback;
struct testclass
{
void testfunc()
{
printf("test\n");
}
};
int main()
{
testclass test;
callback c = std::bind(&testclass::testfunc, &test);
c(1);
}
输出是
test
std::bind 返回一个可调用的目标,如void(void),而回调应存储为void(int)。
为什么我可以这样做?
【问题讨论】:
-
可能是因为bind返回
A function object of unspecified type...