Can someone explain the following code? How can the third parameter be a function with no parentheses? I understand how to use it but am a little confused by the lack of parentheses. Under what circumstances can you do this? Thanks.
1 2 3 4 5 6 7 8
bool alpha(Name x, Name y)
{
if (x.name < y.name)
returntrue;
elsereturnfalse;
}
sort(array.begin(), array.end(), alpha);
A function name with parentheses is a function call. You don't want that. You want to pass the function itself so that std::sort can use it to compare elements with.