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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -