1 2 3
|
int elements = 0;
int lastIndex=0;
int *arrayList= new int [elements];
|
Here you are declaring new variables that will only exists inside the constructor. If ArrayList has the member variables elements, lastIndex and arrayList just do normal assignment or use the constructor initialization list.
arrayList&[lastIndex]=n;
The & should not be there and shouldn't you increase elements and/or lastIndex in that function?
int [] arr&
What is this? An int array? In that case it should be
int arr[]
. arr is actually a pointer to an int so
int* arr
will do the same thing.
int [] arr2;= new ArrayList[arr->length*2];
This has 3 problems.
1. When you have dynamically allocated raw arrays in C++ you have a pointer to the first element in the array. Replace [] with * to make arr2 a pointer.
2. That semicolon after arr2 shouldn't be there.
3. arr is just a pointer so there is no way to know the length of the array pointed to. What you can do is pass the length as an extra argument to the function.
If size is a member function of ArrayList you need to write
int ArrayList::size()
when you define the function.
It's obvious that you are used to program in Java ;) Note that the equivalent of ArrayList in C++ is std::vector.