hi all~
i met some problem when coding a template class, the trouble is one of its method(const method) due to grab the data with position specified which return the type the same as template one, but when i compiled the compiler report an error which said: "warning: argument to non-pointer type 'int' from NULL". i wonder what this means and want the solution to my method, here is the code:
Code:
template <class T>
class LinkedList
{
public:
LinkedList();
~LinkedList();
void clear();
bool isEmpty() const;
int getLength() const;
T getData(int pos) const;
int find(T t) const;
bool insert(int pos, T t);
bool remove(int pos);
void trace() const;
private:
LinkedListNode<T>* __first;
};
template <class T>
T LinkedList<T>::getData(int pos) const
{
if (pos < 0) return NULL;
int _len = 0;
LinkedListNode<T>* _ptNode = __first;
while (_ptNode)
{
if (_len == pos) return _ptNode->data;
_ptNode = _ptNode->next;
_len++;
}
return NULL;
}
int main()
{
LinkedList<int> myLinkedList;
int num = 10;
for (int i=0; i<num; i++)
{
myLinkedList.insert(i, i);
}
myLinkedList.remove(9);
myLinkedList.getData(1); // Error here !
myLinkedList.trace();
return 0;
}
thanx !