how to get float type array size

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.
what's an example of passing size along array pointer or using vector to get the size?
what's an example of passing size along array pointer
bool Polygon::setPoints(int numPoints, float xValues[], std::size_t xLength, float yValues[], std::size_t yLength)

using vector to get the size?
1
2
3
4
bool Polygon::setPoints(int numPoints, std::vector<float> xValues, std::vector<float> yValues) 
{
    auto xLength = xValues.size();
    //http://www.mochima.com/tutorials/vectors.html 
I got the idea. But if the signature of the method cannot be changed, how can I deal with this?
What does numPoints stands for? Isn't it number of points/length of arrays?
Topic archived. No new replies allowed.