From: ike@iceland.freeshell.org   
      
   On 2012-10-19, Vianney Lan?on wrote:   
   > Hello,   
   >   
   > while compiling our code we found that a wrong constructor was called.   
   >   
   > The code was something like that.   
   >   
   >   
   > #include    
   > struct Toto   
   > {   
   > Toto(unsigned short a[2]){ x=a[0]; y=a[1];}   
   > unsigned short x, y;   
   > };   
   > void print(const Toto& toto)   
   > {   
   > std::cout< }   
   > int main()   
   > {   
   > print(false); // <= convert false to Toto   
   > return 0;   
   > }   
   >   
   >   
   > Because the constructor of Toto is not explicit it is normal that   
   > unsigned short[4] can be converterd to Toto.   
   >   
   > But I do not understand by what mechanisme the bool value false can be   
   > convert into unsigned short[4].   
   >   
   > Because it doesn't compile if i change the value from false to true it   
   > 's probably because of some convertion from false to 0 literal.   
   >   
   > This code, compile on VC++10 & commeau online so i guess, it probalby   
   > resepect the standard. Do you have any clue how?   
      
   The type of the parameter in Toto(unsigned short a[2]) decays into a   
   pointer-to-short. The declaration is equivalent to Toto(unsigned short *a);   
   0, a null pointer constant, is accepted as a pointer-to-short.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|