Skip to content

Instantly share code, notes, and snippets.

@gsauthof
Last active July 2, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsauthof/2750fcaca5997c6dee3d9ba888b2063b to your computer and use it in GitHub Desktop.
Save gsauthof/2750fcaca5997c6dee3d9ba888b2063b to your computer and use it in GitHub Desktop.
Address of function example
/*
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