I'm trying to pass an aggregate that stores functions as designated initializers with no success.
This is what I tried:
typedef struct Handlers { std::function<void()> func1 = nullptr; std::function<void()> func2 = nullptr; std::function<void()> func3 = nullptr; std::function<void()> func4 = nullptr; } Handlers; class Person { public: Person(const char *name, uint16_t age, Handlers &&handlers); void doSomething(); };
this is how i'm trying to pass the functions
int main(int argc, char *argv[]){ Person p1("Guy", 28, { .func1 = []() {}, .func2 = []() {}, .func3 = []() {}, .func4 = []() {} });}
One of the error messages:
no known conversion for argument 3 from ‘<brace-enclosed initializer list>’ to ‘Handlers&&’ 35 | Person(const char *name, uint16_t age, Handlers &&handlers);