hii,
this is my .h ,file :
/*
* sortedlist.h
*
* Created on: Jan 16, 2011
* Author: saeed hardan
*/
#ifndef SORTEDLIST_H_
#define SORTEDLIST_H_
#include <iostream>
#include <functional>
namespace mtm {
template< typename T, typename Compare = std::less<T> >
class SortedList {
private:
struct ListNode {
ListNode *next;
ListNode *prev;
T data;
ListNode() {
next = prev = NULL;
}
}*head,*tail;
int length;
Compare comp;
void addFirst(T element){}
void removeFirst(T element){}
void removeLast(T element){}
public:
/******************************************************************************
*
*****************************************************************************/
class SortedListIterator {
private:
ListNode *cur;
public:
SortedListIterator() :
cur(NULL) {
}
SortedListIterator(ListNode *pos) :
cur(pos) {
}
SortedListIterator(const SortedListIterator& iter){
cur = iter.cur;
}
T& operator*(){
return cur->data;
}
SortedListIterator& operator++(){ // Prefix
cur=cur->next;
return (*this);
}
SortedListIterator operator++(int){ // Postfix
SortedListIterator curPosition((*this));
++(*this);
return curPosition;
}
friend bool operator==
(SortedListIterator& iterator1, SortedListIterator& iterator2){
if (iterator1.cur == iterator2.cur){
return 1;
}
return -1;
}
friend bool operator!=
(SortedListIterator& iterator1, SortedListIterator& iterator2){
return !(iterator1==iterator2);
}
};
/******************************************************************************
*
*****************************************************************************/
typedef SortedListIterator iterator;
iterator begin() {
iterator iter(head);
return iter;
}
iterator end() {
iterator iter(NULL);
return iter;
}
/******************************************************************************
*
*****************************************************************************/
SortedList():head(new ListNode),tail(head),length(0),comp(){}
explicit SortedList(const Compare& c):
head(new ListNode),tail(head),length(0),comp(c){}
SortedList(const SortedList& sortedList){}
~SortedList(){}
SortedList& operator=(const SortedList& sortedList){ }
/******************************************************************************
*
*****************************************************************************/
int size() const{}
void add(T element){ }
bool contains(T element){}
bool remove(T element){}
};
}
#endif /* SORTEDLIST_H_ */
i get this error when i try to compile it , with g++ :
sorted_list_example.cpp:49: error: no match for ‘operator!=’ in ‘iterator != mtm::SortedList<T, Compare>::end() [with T = int, Compare = std::less<int>]()’
sorted_list.h:95: note: candidates are: bool mtm::operator!=(mtm::SortedList<int, std::less<int> >::SortedListIterator&, mtm::SortedList<int, std::less<int> >::SortedListIterator&)
sorted_list_example.cpp:75: error: no match for ‘operator!=’ in ‘iterator != mtm::SortedList<T, Compare>::end() [with T = int, Compare = AbsoluteComparer]()’
sorted_list.h:95: note: candidates are: bool mtm::operator!=(mtm::SortedList<int, AbsoluteComparer>::SortedListIterator&, mtm::SortedList<int, AbsoluteComparer>::SortedListIterator&)
sorted_list.h:95: note: bool mtm::operator!=(mtm::SortedList<int, std::less<int> >::SortedListIterator&, mtm::SortedList<int, std::less<int> >::SortedListIterator&)
any ideas ? is my SortedListIterator , written correctly ?
thnx