Reputation: 6058
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];
}
Upvotes: 0
Views: 61
Reputation: 361812
You have to write that as:
template<typename T>
T ABList<T>::retrieve (int pos) throw (ListException)
{
//...
}
because ABList
a 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 .h
file, and member functions in .cpp
would not work in case of templates.
Upvotes: 2