c++ - In regards to array size calculation -
possible duplicate:
can explain template code gives me size of array?
hi, looking @ answer posted here:
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
Post a Comment