c++ - In regards to array size calculation -


possible duplicate:
can explain template code gives me size of array?

hi, looking @ answer posted here:

computing length of array

copied here:

template <typename t, std::size_t n> std::size_t size(t (&)[n]) {     return n; } 

can 1 pls explain me significance of (&) ?

the & says array passed reference. prevents type decaying pointer. without passing reference decay, , no information array size.

non-template example:

void foo( int (&a)[5] ) {     // whatever }  int main() {     int x[5];     int y[6];      foo( x );           // ok     //foo( y );         // !incompatible type } 

cheers & hth.,


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -