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)
{
}
You could also use a global variable or a class attribute.
size_t size = 100;
void functionName(HANDLE* arr)
{
//size will be visible here and in any other
// functions and you can change its value during run-time
}