I'm trying to build a doublylinkedlist template class. However, when define constructor and destructor inside template class. The complier gives out errors. when comment out the constructor and destructor, these errors are gone. What's wrong with my constructor and destructor? They should be working in ordinary classes... Here is my code. Thank you in advance.
template<typename Key>
class DoublyLinkedList{
public:
class const_iterator;
class iterator;
DoublyLinkedList(){
Head_ = new Node;
Tail_ = new Node;
Head_->Next_ = Tail_;
Tail_->Prev_ = Head_;
}
~DoublyLinkedList(){
clear();
delete Head_;
delete Tail_;
}
bool push_front(const Key& key);
bool push_back(const Key& key);
bool pop_front(const Key& key);
bool pop_back(const Key& key);
size_t size() const { return Size_; }
bool empty() const { return Size_ == 0; }
iterator begin();
iterator end();
const_iterator cbegin() const;
const_iterator cend() const;
void clear();
iterator insert(iterator itr, const Key& key);
iterator erase(iterator itr);
iterator erase(iterator start, iterator end);
private:
struct Node{
Key Key_;
Node* Next_;
Node* Prev_;
Node(const Key& key = Key(),
Node* next = nullptr,
Node* prev = nullptr):
Key_(key), Next_(next), Prev_(prev){}
};
Node* Head_ ;
Node* Tail_ ;
size_t Size_ = 0;
};
Aucun commentaire:
Enregistrer un commentaire