Sunday, 25 August 2013

Unqualified IDs and Template Classes

Unqualified IDs and Template Classes

I've been writing a custom class for a circular list, called CList. I've
been basing it off a homework assignment I completed a long while ago with
a lot of copy paste so I don't exactly remember exactly everything I've
been writing works.
Anyway, simply trying to include the .h file causes me the error on the
using namespace std line:
main.cpp:11: error: expected unqualified-id before ';' token
As well as two errors pointing to a function in my code:
In file included from main.cpp:9:
CList.h:119: error: non-template 'CIterator' used as template
CList.h:119: note: use 'CList<T>::template CIterator' to indicate that it
is a template
This is the function in question:
template <class T>
typename CList<T>::CIterator<T> CList<T>::push(T const& v)
{
size++;
Node<T>* p = new Node<T>(v);
if (this -> size_ == 1)
{
head = p;
tail = p;
p -> next = p;
p -> prev = p;
}
else
{
tail -> next = p;
p -> next = head;
p -> prev = tail;
head -> prev = p;
tail = p;
}
return CIterator(p);
}
I don't really understand what the error here is. I am telling the
function to return a CIterator of a CList, and am denoting that this
function is part of the CList class. That is what I understand when I read
the line
typename CList<T>::CIterator<T> CList<T>::push(T const& v)
Why does it think that CIterator is the template when clearly T is the
template? I'm just confused.

No comments:

Post a Comment