Monday, December 1, 2008

Method that returns the size of any array declared in stack

template<typename T, size_t N>

size_t mysizeof(T(&)[N])

{

return N;

}

On this note, here is a way to pass an array by C++ reference style where A has no l-value

void PassArrayByRef(int(&A)[10])

{

// A++; // Illegal

}

The usual way to pass an array where “A” is a pointer

void PassArrayByPtr(int A[10])

{

A++;

}

No comments: