Comparators & Function Passing

I’m not clear with this function passing & accepting the function. What’s that bool (&cmp) etc? I’ve watched this video several times, it’s still confusing for me. Please help me out. Thanks

hello @gambhirrahul0

we can pass function to another function , like we pass a variable to some function.

for example->
void f(int x){

}
int y=2;
f(y)

here we are passing variable y to function f. right?
and the function definition i.e
void f(int x){

}
is telling us that this function recieve a variable of int type and it will be known as x inside this function.

in similar way if we can pass a function to other function

void y(){

}

let say this is a function and we want to pass this function to another function f.
then f definition will look like
void f ( void y() ){ // this deifiniton is telling that function f will recieve
a function

}

f(y) // calling function f by passing function y as param.

now if we want to pass function by reference then we need to use & sign before function.
void f ( void (&y)() ){ // this deifiniton is telling that function f will recieve
a function

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.