The standard stream types don't overload <<
for function pointers, only for regular pointers. You see the value 1 because a function pointer is implicitly convertible to bool
, and there is an overload for bool
, so that is chosen.
To print the address, you could convert it to a regular (object) pointer:
cout << reinterpret_cast<void*>(fooptr) << std::endl;
Note that this isn't completely portable: according to the standard, it's conditionally-supported, with an implementation-defined meaning. But it should give the expected address on any sensible implementation on mainstream platforms that store functions in regular memory. For more portability, you might convert to intptr_t
or uintptr_t
; but you'd need a bit of extra work if you want it to be formatted like a pointer.