Class type conversion during parameter passing: why typecasting function is not called
<p>Here is my code:</p>

<pre><code>  1     #include &lt;cstdio&gt;
  2 
  3     struct Foo;
  4 
  5     struct Bar {
  6         Foo *foo;
  7         Bar(const Foo&amp; fo) {
  8             printf("In Bar copy_contr\n");
  9         }
 10 
 11         Bar&amp;  operator=(Foo&amp; fo) {
 12             printf("In Bar assignment\n");
 13             this-&gt;foo = &amp;fo;
 14         }
 15     };
 16 
 17     struct Foo {
 18         Bar *bar;
 19         Foo() {
 20             printf("In default\n");
 21         }
 22 
 23         Foo(const Bar&amp; b) {
 24             printf("In Foo copy constructor\n");
 25         }
 26 
 27         operator Bar() {
 28             printf("In typecast from Foo to Bar\n");
 29             return *(this-&gt;bar);
 30         }
 31 
 32     };
 33 
 34 
 35     int f(Bar b) {
 36         return 0;
 37     }
 38 
 39     int main() {
 40         Foo fo;
 41         f(fo);
 42         Bar *b = &amp;static_cast&lt;Bar&gt;(fo);
 43 
 44         return 0;
 45     }
</code></pre>

<p>Here is the print out:</p>

<pre><code>In default
In typecast from Foo to Bar
In Bar copy_contr
</code></pre>

<p>I am confused at the 3rd printout: how come copy constructor is called, it should be type casting, there is specific static_cast there.</p>

<p>I also have an interesting find - if I comment out line27 - line30, basically make disappear the typecasting function, the printout changes to 
    In default
    In Bar copy_contr
    In Bar copy_contr</p>

<p>So it seems the compiler has some mechanism to search some conversion function in some order, anyone has standard hardy to tell what is the mechanism?</p>

<p>I am using g++ v4.1.2.</p>

<p>Thanks!</p>
