How to print function pointers with cout?
<p>I want to print out a function pointer using cout, and found it did not work.
But it worked after I converting the function pointer to (void *), so does printf with %p, such as </p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int foo() {return 0;}

int main()
{
    int (*pf)();
    pf = foo;
    cout &lt;&lt; "cout &lt;&lt; pf is " &lt;&lt; pf &lt;&lt; endl;
    cout &lt;&lt; "cout &lt;&lt; (void *)pf is " &lt;&lt; (void *)pf &lt;&lt; endl;
    printf("printf(\"%%p\", pf) is %p\n", pf);
    return 0;
}
</code></pre>

<p>I compiled it with g++ and got results like this:</p>

<blockquote>
  <p>cout &lt;&lt; pf is 1<br>
  cout &lt;&lt; (void *)pf is 0x100000b0c<br>
  printf("%p", pf) is 0x100000b0c</p>
</blockquote>

<p>So what does cout do with type int (*)()? I was told that the function pointer is treated as bool, is it true?
And what does cout do with type (void *)?</p>

<p>Thanks in advance.</p>

<p>EDIT: Anyhow, we can observe the content of a function pointer by converting it into (void *) and print it out using cout.
But it does not work for member function pointers and the compiler complains about the illegal conversion. I know that member function pointers is rather a complicated structure other than simple pointers, but how can we observe the content of a member function pointers?</p>
