I just self-taught myself C++. I've got all the basics down, but I'm still working out some of the nuances.
Basically, I'm passing an array into a function, and I need the function to be able to pass the length of the array to an integer. I'm using
int len = sizeof(array)/sizeof(array[0])
When I use this code in the main function, it works just fine, assigning the length of the array to len. However, when I pass the array as an argument to a function, and then run the code inside the function, it always evaluates sizeof(array) as 4 bytes, instead of 4 bytes * array length. So my int always ends up being assigned 1.
Is there a way to figure out the length of an array thats been passed to a function? Or am I just stuck passing the length as an additional argument?
I tried passing the array by reference, but I got a compiler error saying I can't have an array of references in my function declaration. Can I change the syntax so the compiler identifies it as a reference to an array, instead of an array of references? And would that even solve my length problem?
The syntax I'm using is for my function declaration/definition is
MyFunc(&array[])