Using
ArrayList<T>::ArrayList(const ArrayList<T>& list)
as your constructor signature, to pass arraylist as a const reference. This is the correct signature for the copy constructor. Both the implementation code and the call code should not change unless you change the list inside your ctor.
When you make an ArrayList<T>::ArrayList(ArrayList<T> list) , you create a temporary copy of the entire ArrayList instance. (You should not do this for ctors, since it will cause infinite recursion, since a new copy of list will use the same function definition, etc.).
ArrayList<T>::ArrayList(ArrayList<T>& list) passes the list as a reference, that is, it is no longer what is often called "pass by value", and works on the exact version of the list from the calling code.
Accepting a reference to a constant in a function, you say that the function will not change the contents of the link (i.e. it will not perform any modifying operations on it: it will be limited only by const access). You should read about const , references, and copy constructors before moving on.
Update:
To pass by value or reference, you can access the elements through the obj.member syntax. If you specify a pointer of type ArrayList<T>::ArrayList(ArrayList<T>* list) , you will need to use the list->member or (*list).member , not to mention that it is checked first if there is list 0 / nullptr (you cannot dereference null pointers).
You mix syntax for pointers and syntax for values / references. convert all your list->x to list.x since you are not passing the list argument with pointers.
See this for different walkthroughs: http://ideone.com/3c5mJ
source share