If I have the following function in C++:
void functionName(HANDLE arr[100])
{
}
HANDLE hHandles[100];
functionName(hHandles);
Is there any way to know the size of 'arr' inside the functionName? (Without hardcoding it there)
If I have the following function in C++:
void functionName(HANDLE arr[100])
{
}
HANDLE hHandles[100];
functionName(hHandles);
Is there any way to know the size of 'arr' inside the functionName? (Without hardcoding it there)
Use template to catch the N in T[N]
template <size_t N>
void function(HANDLE (&arr)[N])
{
std::cout << N << " is here\n";
}
No. Unless you have put a delimiter at the end yourself before passing. In case of strings (which are character arrays)the delimiter is the null character '\0' so the size can be checked. But normally for arrays this can't be done.
Consider sending the size as a separate parameter instead.
void functionName(HANDLE arr[100], size_t size)
{
}
std::vector.