Here I have the code
void foo(std::function<int(int)> stuff){
//whatever
}
and it is called with
auto fct = [](int x){return 0;};
foo(fct);
Which works great. However, when I change foo
to
void foo(std::function<int(int)>& stuff){ // only change is that it is passed by reference
//whatever
}
The code doesn't compile. Why is this the case? I know we can just pass the object to a reference parameter directly, we don't need the &
operator like for pointers. Why can't you pass std::function types by reference?