Created
June 28, 2015 10:23
-
-
Save krysseltillada/a1773cc9118dae4e9dea to your computer and use it in GitHub Desktop.
function pointer parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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