Passing an array to a function and get the number of elements

I am writing a function that receives a one-dimensional array as an argument but I have a problem when I try to get the number of elements of the array. When I compile I get the error message as below. What is wrong?

Error 2 error C2228: left of '.size' must have class/struct/union d:\visual studio 2013 csce 221 projects\my_stack\my_stack\my_stack.cpp 92 1 My_stack

1
2
3
4
5
6
    void f(int x[])
    {
	for (int i = 0; i <= x.size() - 1; i++)
	{
	}
    }

Arrays don't have a size method. You can pass the size of the array to your function void f(int x[], unsigned size); or you can use std::array.


http://www.cplusplus.com/reference/array/array/?kw=array
Last edited on
Topic archived. No new replies allowed.