When I try to get the size of float type array, my complier keep sending me:
sizeof on array function parameter will return size of "float" instead of 'float[]', what does it mean? and how can I get the array size of xValues[] and yValues[] without using the current method?
1 2 3
bool Polygon::setPoints(int numPoints, float xValues[], float yValues[]) {
int xLength = sizeof(xValues) / sizeof(xValues[0]);
int yLength = sizeof(yValues) / sizeof(yValues[0]);
float xValues[] is another way to write float* xValues. When array is passed to function it decays to pointer losing all additional type information (like array size). So sizeof(xValues) returns size of pointer which is not what you want.
You can:
a) pass size along your array pointers.
b) make your function take concrete specific array type like float xValues[10]. Obviously it prevents you from passing arrays of other size and dynamically allocated arrays.
c) Drop arrays and use proper containers which at least know teir size. Vector for example.