#include <cstdlib>
using namespace std;
int main()
{
int arrayTest[512];
int size = arrayTest.size();
for(int a = 0;a<size;a++)
{
//stuff will go here
}
}
What am I doing wrong here becuase the plan is to just fill the array with some numbers
Do this:
C-style arrays don't have member function. They don't have any notion of class.
Anyway, better use
std::array
:which looks like what you wanted. Now you can use index
i
to access elements ofarrayTest
asarrayTest[i]
wherei
can vary from0
tosize-1
(inclusive).Arrays don't have members. You have to use something like:
Better yet, if you must work with normal arrays instead of
std::array
, use a helper function. This also has the advantage of not breaking when you attempt it on a pointer instead of an array:arrayTest
is not a class or struct but an array and it does not have member functions, in this case this will get your the size of the array:although if your compiler supports C++11 than using std::array would be better:
as the document linked above shows you can also use range for loop to iterate over the elements of a std::array:
If you are stuck with arrays you can define your getArraySize function:
seen here: http://www.cplusplus.com/forum/general/33669/#msg181103
std::array remains the better solution.