I am getting an error saying ‘T’ does not name a type. I am confused as to what this means. I thought i declared it in the class saying Virtual T?
template <class T>
class ABList : public ABCList<T> {
private:
T a [LIST_MAX];
int size;
public:
ABList ();
virtual bool isEmpty ();
virtual int getLength ();
virtual void insert (int pos, T item);
virtual T remove (int pos);
virtual T retrieve (int pos);
};
.
T ABList::retrieve (int pos) throw (ListException)
{
if (pos <= 0 || pos >= count)
throw new ListException();
return item[pos – 1];
}
You have to write that as:
because
ABLista class template.Note that you’ve to define the member functions in the same file itself in which you’ve defined the class template. Defining class template in
.hfile, and member functions in.cppwould not work in case of templates.