Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created June 28, 2015 10:23
Show Gist options
  • Save krysseltillada/a1773cc9118dae4e9dea to your computer and use it in GitHub Desktop.
Save krysseltillada/a1773cc9118dae4e9dea to your computer and use it in GitHub Desktop.
function pointer parameter
#include <iostream> /// std::cout; std::endl;
void useBigger (const std::string &s1, const std::string &s2, /// function useBigger has a parameters of two reference to const string and one pointer type that has paramters pf two const string and returns bool and returns void
bool (*pf)(const std::string &, const std::string &))
{
bool valid = pf (s1, s2); /// equivalent as lengthCompare (s1, s2);
std::cout << __func__ << " is called "
<< valid <<std::endl;
}
bool lengthCompare (const std::string &s1, const std::string &s2)
{
if (s1.size() > s2.size())
return true;
else
return false;
}
int main()
{
useBigger ("hello", "assholes", lengthCompare); /// passes the two argument strings and one function
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment