Last active
July 2, 2016 10:59
-
-
Save gsauthof/2750fcaca5997c6dee3d9ba888b2063b to your computer and use it in GitHub Desktop.
Address of function example
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
/* | |
Illustrate how the & operator can be omitted when getting a function pointer. | |
In reply to: https://www.youtube.com/watch?v=z-kUhwANrIw | |
2016, Georg Sauthoff | |
*/ | |
#include <iostream> | |
#include <functional> | |
#include <typeinfo> | |
int do_something(int i) | |
{ | |
return 5 + i; | |
} | |
int main() | |
{ | |
// std::cout << std::invoke(do_something, 5) << '\n'; | |
auto f1 = do_something; | |
std::cout << typeid(f1).name() << '\n'; | |
auto f2 = &do_something; | |
std::cout << typeid(f2).name() << '\n'; | |
return 0; | |
} | |
/* | |
output: | |
$ ./a.out | c++filt -t | |
int (*)(int) | |
int (*)(int) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment