admin管理员组文章数量:1334856
I have below snipped code works properly. But in my opinion it shouldn't work.
#include <functional>
template <class T> void run(std::function<void(T *)> fun, T *obj) { fun(obj); }
struct Foo {
void bar() {}
};
int main() {
Foo foo;
std::function<void(Foo *)> fun = &Foo::bar;
run(fun, &foo); // works
}
- The
bar()
function is not compatible with the expected blueprint.bar()
function accepts no parameter butstd::functional
acceptsT *
. fun
variable is defined only&Foo::bar
. How compiler knows, it is function offoo
object?
本文标签: C function callback for class functionStack Overflow
版权声明:本文标题:C++ function callback for class function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742375138a2463008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论