template <typename a, typename ... b>
class events
{
public:
typedef std::function<void( a arg, b ... argx)> OnSomethingHandler;
events(OnSomethingHandler Handler)
{
handlers_.push_back(Handler);
}
void operator ()()
{
for(auto i = handlers_.begin(); i != handlers_.end(); ++i)
(*i)();
}
private:
std::vector<OnSomethingHandler> handlers_;
void AddHandler(OnSomethingHandler Handler)
{
handlers_.push_back(Handler);
}
void TriggerEvents()
{
for(auto i = handlers_.begin(); i != handlers_.end(); ++i)
(*i)();
}
};
how can i had paramaters to lambda?
i'm trying, but i get errors:
int main()
{
events my_foo([](int a, int b){
std::cout << (a+b) << std::endl;
});
my_foo(4,5);
return 0;
}
errors messages:
"C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp||In function 'int main()':|
C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|46|error: missing template arguments before 'my_foo'|
C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|46|error: expected ';' before 'my_foo'|
C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|48|error: expected primary-expression before ')' token|
C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|48|error: expected ';' before ')' token|
C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|51|error: 'my_foo' was not declared in this scope|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 1 seconds) ===|"