Guys I have this little problem here. I have a function that takes an int array as parameter, and in my main() i declare a fixed-size array and pass it into that function, but in that function sizeof(arr) is not the true size. Should be a silly issue. Any advice is greatly appreciated. Below is the code(very straightforward):
Nope. Use a vector or pass an additional parameter. Personally I'd go with a vector since then you don't have to worry about remembering to pass the parameter.
Actually, I didn't think of Duoas's solution at first, but now that he has mentioned that, it can be turned into a proxy/stub/whats-it to the actual function call like this:
1 2 3 4 5 6 7 8 9 10 11
template <size_t N>
inlineint missingNumberStub(int (&arr)[N])
{
return missingNumberActual(N, arr);
}
int missingNumberActual(size_t N, int arr[])
{
for (size_t n = 0; n < N; n++)
...
}
This should alleviate (most of) the wastefulness from instantiating templates when you call missingNumberStub with different arrays.