Errors with a Template in C++ regarding operators
<p>In my project, I am using a header file for an arrayList. During the main method, I initialize an object of type arrayList where FriendToken is another class defined in my project. However, this gives me quite a few errors while compiling arrayList.h. Apparently, I cannot use the built-in copy method and the operator == is unrecognized for an object of type FriendToken. Should I overload the == operator for FriendToken and if so, how should I do that?</p>

<p>Both errors are marked in the body ArrayList.h.</p>

<p>ArrayList.h: </p>

<pre><code>#ifndef arrayList_h
#define arrayList_h

#include "linearList.h"

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;ostream&gt;

using namespace std;
template&lt;class T&gt;
class arrayList : public linearList&lt;T&gt; 
{
public:
    // constructor, copy constructor and destructor
    arrayList(int initialCapacity = 10);
    arrayList(const arrayList&lt;T&gt;&amp;);
    ~arrayList() {delete [] element;}
    // ADT methods
    bool empty() const {return listSize == 0;}
    int size() const {return listSize;}
    T&amp; get(int theIndex) const;
    int indexOf(const T&amp; theElement) const;
    void erase(int theIndex);
    void insert(int theIndex, const T&amp; theElement);
    void output(ostream&amp; out) const;
    void changeLength1D(T*&amp; a, int oldLength, int newLength);
    // additional method
    int capacity() const {return arrayLength;}
protected:
    void checkIndex(int theIndex) const;
    // throw illegalIndex if theIndex invalid
    T* element;      // 1D array to hold list elements
    int arrayLength;       // capacity of the 1D array
    int listSize;          // number of elements in list
};
template&lt;class T&gt; 
arrayList&lt;T&gt;::arrayList(int initialCapacity)
{
    // Constructor.
    arrayLength = initialCapacity;
    element = new T[arrayLength];
    listSize = 0;
}
template&lt;class T&gt;
arrayList&lt;T&gt;::arrayList(const arrayList&lt;T&gt;&amp; theList)
{
    // Copy constructor.
    arrayLength = theList.arrayLength;
    listSize = theList.listSize;
    element = new T[arrayLength];
    copy(theList.element, theList.element + listSize, element); 
}
template&lt;class T&gt;
void arrayList&lt;T&gt;::checkIndex(int theIndex) const
{
    // Verify that theIndex is between 0 and 
    // listSize - 1.
    if (theIndex &lt; 0 || theIndex &gt;= listSize)
    {
        cout &lt;&lt; "index = " &lt;&lt; theIndex &lt;&lt; " size = " 
            &lt;&lt; listSize;
    } 
}
template&lt;class T&gt;
T&amp; arrayList&lt;T&gt;::get(int theIndex) const
{
    // Return element whose index is theIndex.
    // Throw illegalIndex exception if no such
    // element.
    checkIndex(theIndex);
    return element[theIndex];
}
template&lt;class T&gt;
int arrayList&lt;T&gt;::indexOf(const T&amp; theElement)const
{
    // Return index of first occurrence of theElement.
        // search for theElement
        int theIndex = (int) (find(element, element
        + listSize, theElement) - element);
    // check if theElement was found
    if (theIndex == listSize)
        return -1; // not found
    else return theIndex; 
}
template&lt;class T&gt;
void arrayList&lt;T&gt;::erase(int theIndex)
    {// Delete the element whose index is theIndex.
    checkIndex(theIndex);
    // valid index, shift elements with higher index
//PROBLEM********************************************
    copy(element + theIndex + 1, element + listSize,element + theIndex);
    element[--listSize].~T(); // invoke destructor
}
template&lt;class T&gt;
void arrayList&lt;T&gt;::insert(int theIndex, const T&amp; theElement)
{
    // Insert theElement.
    if (theIndex &lt; 0 || theIndex &gt; listSize)

    {// invalid index
        // code to throw an exception comes here
    }
    // valid index, make sure we have space
    if (listSize == arrayLength)
    {
        // no space, double capacity
        changeLength1D(element, arrayLength, 
        2 * arrayLength);
        arrayLength *= 2;
    }
    // shift elements right one position
//PROBLEM***************************************
    copy_backward(element + theIndex, element + listSize, element + listSize + 1);
    element[theIndex] = theElement;
    listSize++;
}
template&lt;class T&gt;
void arrayList&lt;T&gt;::output(ostream&amp; out) const
{
    // Put the list into the stream out.
    copy(element, element + listSize, ostream_iterator&lt;T&gt;(out, "  ")); 
}
template &lt;class T&gt;
ostream&amp; operator&lt;&lt;(ostream&amp; out, const arrayList&lt;T&gt;&amp; x)
{x.output(out); return out;}

template&lt;class T&gt;
void changeLength1D(T*&amp; a, int oldLength, int newLength)
{
    if (newLength &lt; 0)
        throw illegalParameterValue();
    T* temp = new T[newLength];     
    // new array
    int number = min(oldLength, newLength); 
    // number to copy
    copy(a, a + number, temp);
    delete [] a;                    
    // deallocate old memory
    a = temp;
}


#endif
</code></pre>

<p>FriendToken.h</p>

<pre><code>#ifndef FriendToken_h
#define FriendToken_h

#include &lt;string&gt;

using namespace std; 

class FriendToken
{
private:
    string birthDate, name, homeTown;
public:
    FriendToken(string birthDate = "01/01", string name = "John, Smith", string homeTown = "New York");
    string getBirthDate();
    string getName();
    string getHomeTown();
    bool equals(FriendToken a);
};

#endif
</code></pre>

<p>FriendToken.cpp</p>

<pre><code>#include "FriendToken.h"
#include &lt;string&gt;

using namespace std;

FriendToken::FriendToken(string birthDate, string name, string homeTown)
{
    this-&gt;birthDate = birthDate;
    this-&gt;name = name;
    this-&gt;homeTown = homeTown;
}
string FriendToken::getBirthDate()
{
    return birthDate;
}
string FriendToken:: getName()
{
    return name;
}
string FriendToken::getHomeTown()
{
    return homeTown;
}
bool FriendToken::equals(FriendToken a)
{
    return (name == a.getName()) &amp;&amp; (homeTown == a.getHomeTown()) &amp;&amp; (birthDate == a.getBirthDate());
}
</code></pre>
