【发布时间】:2017-11-22 09:16:45
【问题描述】:
我需要将非静态成员函数传递给参数
class Foo {
void f() {}
void caller() {
//calling of g() happens here using f()
}
};
Class Goo {
std::map<int,std::vector<std::function<void()>>>> m;
void g(int i, std::function<void()> const& h) {
m[i].push_back(h);
}
}
我试着打电话
g(f), g(Foo::f), g(std::make_fn(Foo::f), g(std::make_fn(Foo:f, this), g(this.f)
并且还尝试将其作为参考传递(尽管应该)。
我得到的错误是无效使用非静态成员函数。
编辑:我在g() 后面添加了功能
【问题讨论】:
-
请注意,您不能将引用存储在容器中。如果您想要引用,请改用指针。在这种情况下,这是没有意义的。只存储值。