c++ - Can you use a reference operator with a fuction? -
so started learning reference (&) , dereference (*) operators in c++ , have question.
so, let's have hypothetical function:
int foobar(int foo, int bar) { return foo+bar; }
could possibly call function regular variable reference operator (&)?
something this:
int normalfunction(int &referencedfunction()) { return referencedfunction(somevariable); }
it sounds want pass function function. simplest way is:
#include <functional> // ... int normalfunction( std::function<int()> referenced_function ) { return referenced_function(); }
the template parameter std::function
return type, followed parameter list in parentheses. int()
means function returning int , taking no arguments.
Comments
Post a Comment