Questions about `std::cout << &std::hex << 123 << std::endl;`

Viewed 106
1 Answers

The name of a function decays into a pointer to that function. So std::cout << std::hex uses the stream inserter that takes a pointer to a function that takes an std::ios_base& and returns an std::ios_base&. The stream inserter simply calls the function.

Function pointers have another peculiar property: when you write &std::hex, it evaluates to the address of the function. Same for &&std::hex, &&&&std::hex, etc. They all mean the same thing.

Related