home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,877 of 33,346   
   Marc to Helmut Zeisel   
   Re: could not deduce template argument f   
   31 Jan 12 15:16:55   
   
   4884188b   
   From: marc.glisse@gmail.com   
      
   Helmut Zeisel  wrote:   
      
   > Why does the code below not compile?   
   >   
   > VC 2010 says   
   >   
   >   error C2784: 'void f(double [m][n])' : could not deduce template   
   > argument for 'double [m][n]' from 'double [2][3]'   
   >   
   > GCC 4.5.3 says   
   >   
   >  error: no matching function for call to `f(double [2][3])'   
   >   
   > Explicitely saying f<2,3>(a) works in both cases.   
   >   
   >   
   > Helmut   
   >   
   > ===========   
   >   
   > #include    
   >   
   > template void f(double a[m][n])   
      
   You are trying to pass an array by value, that's not possible, the [m]   
   decays to a simple pointer and m can't be deduced. Notice that you can   
   call f<42>(a), the value doesn't matter.   
      
   For proper deduction, you want to pass arrays by reference.   
   template void f(double (&a)[m][n])   
      
   > {   
   >  std::cout << "m=" << m << " n=" << n << std::endl;   
   > };   
   >   
   > int main()   
   > {   
   >  double a[2][3];   
   >  f(a);   
   >  return 0;   
   > }   
      
      
   --   
         [ 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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca