下面的代码片段简单地创建了一个具有三个成员的结构。其中之一是回调函数。我想初始化一个由这些结构组成的数组,但是我不知道语法,在这里我可以拥有具有不同原型的多个回调。
#include <iostream>
#include <functional>
template <typename Func>
struct Foo
{
Foo(int a, int b, Func func):
_a{a},
_b{b},
_func{func}{}
int _a;
int _b;
Func _func;
};
int main() {
auto test = [](){std::cout << "hello\n";};
Foo<std::function<void(void)>> foo(5,10, test);
foo._func();
//array version
//......................
}
这个怎么样
//array version
Foo<std::function<void(void)>> a[] = { {5, 10, test}, {1, 2, test} };
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句