2016-03-01 4 views
-3

Я работаю над файлом, Deque.hpp, который использует класс итератора и Узлов сделать Deque, но я получаю сообщение об ошибке:Неожиданный конец файла ошибок на .hpp Файл

"Error C1004 unexpected end-of-file found "

Кажется, я не могу найти причину этого. Вот мой код.

#ifndef DEQUE_H 
#define DEQUE_H 

#include <iostream> 
#include <new> 
#include <cstdlib> 
#include <algorithm> 

// 
// 
// 

template <typename T> 
class Deque 
{ 
public: 

    Deque(); 
    Deque(const Deque & rhs); 
    ~Deque(); 

    Deque & operator= (const Deque & rhs); 

    Deque(Deque && rhs) : theSize{ rhs.theSize }, head{ rhs.head }, tail{ rhs.tail }; 
    Deque & operator= (Deque && rhs); 


    T & Deque<T>::operator[](int n); 

    Iterator begin(); 
    const_iterator begin() const; 
    Iterator end(); 
    const_iterator end() const; 

    int size() const; 
    bool isEmpty() const; 

    void clear(); 

    T & left(); 
    const T & left() const; 
    T & right(); 
    const T & right() const; 
    void pushLeft(const T & x); 
    void pushLeft(T && x); 
    void pushRight(const T & x); 
    void pushRight(T && x); 
    T & popLeft(); 
    T & popRight(); 
    bool Deque<T>::contains(const T&); 

    struct Node 
    { 
     T data; 
     Node *prev; 
     Node *next; 

     Node(const T & d = T{}, Node * p = NULL, Node * n = NULL) : 
      data{ d }, prev{ p }, next{ n } {} 

     Node(T && d, Node * p = NULL, Node * n = NULL) 
      : data{ std::move(d) }, prev{ p }, next{ n } {} 
    }; 

    class const_iterator 
    { 
    public: 
     const_iterator() : current{ NULL } { } 

     const T & operator*() const; 
     const_iterator & operator++(); 
     const_iterator & operator--(); //! 
     const_iterator operator++ (int); 
     const_iterator operator-- (int); //! 


     bool operator== (const const_iterator & rhs) const; 
     bool operator!= (const const_iterator & rhs) const; 

    protected: 

     Node *current; 

     T & retrieve() const; 

     const_iterator(Node *p) : current{ p } { } 

     friend class Deque<T>; 
    }; 

    class Iterator : public const_iterator 
    { 
    public: 
     Iterator(); 

     T & operator*(); 
     const T & operator*() const; 

     Iterator & operator++(); 
     Iterator & operator--(); //! 

     Iterator operator++ (int); 
     Iterator operator-- (int); //! 

    protected: 
     Iterator(Node *p) : const_iterator{ p } { } 

     friend class Deque<T>; 
    }; 

private: 
    // Insert x before itr. 
    Iterator insert(Iterator itr, const T & x); 

    // Insert x before itr. 
    Iterator insert(Iterator itr, T && x); 

    // Erase item at itr. 
    Iterator erase(Iterator itr); 

    Iterator erase(Iterator from, Iterator to); 

    int theSize; 
    Node *head; 
    Node *tail; 

    void init(); 
}; 

template<typename T> 
inline const T & Deque<T>::const_iterator::operator*() const 
{ 
    return retrieve(); 
} 

template<typename T> 
inline const_iterator & Deque<T>::const_iterator::operator++() 
{ 
    current = current->next; 
    return *this; 
} 

template<typename T> 
inline const_iterator & Deque<T>::const_iterator::operator--() 
{ 
    current = current->prev; 
    return *this; 
} 

template<typename T> 
inline const_iterator Deque<T>::const_iterator::operator++(int) 
{ 
    const_iterator old = *this; 
    ++(*this); 
    return old; 
} 

template<typename T> 
inline const_iterator Deque<T>::const_iterator::operator--(int) 
{ 
    const_iterator old = *this; 
    --(*this); 
    return old; 
} 

template<typename T> 
inline bool Deque<T>::const_iterator::operator==(const const_iterator & rhs) const 
{ 
    return current == rhs.current; 
} 

template<typename T> 
inline bool Deque<T>::const_iterator::operator!=(const const_iterator & rhs) const 
{ 
    return !(*this == rhs); 
} 

template<typename T> 
inline T & Deque<T>::const_iterator::retrieve() const 
{ 
    return current->data; 
} 

template<typename T> 
inline Deque<T>::Iterator::Iterator() 
{ 

} 

template<typename T> 
inline T & Deque<T>::Iterator::operator*() 
{ 
    return const_iterator::retrieve(); 
} 

template<typename T> 
inline const T & Deque<T>::Iterator::operator*() const 
{ 
    return const_iterator::operator*(); 
} 

template<typename T> 
inline Iterator & Deque<T>::Iterator::operator++() 
{ 
    this->current = this->current->next; 
    return *this; 
} 

template<typename T> 
inline Iterator & Deque<T>::Iterator::operator--() 
{ 
    this->current = this->current->prev; 
    return *this; 
} 

template<typename T> 
inline Iterator Deque<T>::Iterator::operator++(int) 
{ 
    Iterator old = *this; 
    ++(*this); 
    return old; 
} 

template<typename T> 
inline Iterator Deque<T>::Iterator::operator--(int) 
{ 
    Iterator old = *this; 
    --(*this); 
    return old; 
} 

template<typename T> 
inline Deque<T>::Deque() 
{ 
    init(); 
} 

template<typename T> 
inline Deque<T>::~Deque() 
{ 
    clear(); 
    delete head; 
    delete tail; 
} 

template<typename T> 
inline Deque & Deque<T>::operator=(const Deque & rhs) 
{ 
    if (this == &rhs) 
     return *this; 
    clear(); 
    for (const_iterator itr = rhs.begin(); itr != rhs.end(); ++itr) 
     pushRight(*itr) 

     return *this; 
} 

template<typename T> 
inline Deque<T>::Deque(Deque && rhs) 
{ 
    rhs.theSize = 0; 
    rhs.head = NULL; 
    rhs.tail = NULL; 
} 

template<typename T> 
inline Deque & Deque<T>::operator=(Deque && rhs) 
{ 
    std::swap(theSize, rhs.theSize); 
    std::swap(head, rhs.head); 
    std::swap(tail, rhs.tail); 

    return *this; 
} 

template<typename T> 
inline T & Deque<T>::operator[](int n) 
{ 
    Iterator itr = begin(); 

    for (int i = 0; i < n; i++) 
    { 
     itr.current = itr.current->next; 
    } 

    return itr.current->data; 
} 

template<typename T> 
inline Iterator Deque<T>::begin() 
{ 
    return{ head->next }; 
} 

template<typename T> 
inline const_iterator Deque<T>::begin() const 
{ 
    return{ head->next }; 
} 

template<typename T> 
inline Iterator Deque<T>::end() 
{ 
    return{ tail->prev }; //changed to -> prev 
} 

template<typename T> 
inline const_iterator Deque<T>::end() const 
{ 
    return{ tail->prev }; 
} 

template<typename T> 
inline int Deque<T>::size() const 
{ 
    return theSize; 
} 

template<typename T> 
inline bool Deque<T>::isEmpty() const 
{ 
    return size() == 0; 
} 

template<typename T> 
inline void Deque<T>::clear() 
{ 
    while (!isEmpty()) 
     popLeft(); 
} 

template<typename T> 
inline T & Deque<T>::left() 
{ 
    return *begin(); 
} 

template<typename T> 
inline const T & Deque<T>::left() const 
{ 
    return *begin(); 
} 

template<typename T> 
inline T & Deque<T>::right() 
{ 
    return *end(); // deleted "--*end" 
} 

template<typename T> 
inline const T & Deque<T>::right() const 
{ 
    return *end(); 
} 

template<typename T> 
inline void Deque<T>::pushLeft(const T & x) 
{ 
    insert(begin(), x); 
} 

template<typename T> 
inline void Deque<T>::pushLeft(T && x) 
{ 
    insert(begin(), std::move(x)); // changed std::move(x)) to x 
} 

template<typename T> 
inline void Deque<T>::pushRight(const T & x) 
{ 
    insert(end(), x); 
} 

template<typename T> 
inline void Deque<T>::pushRight(T && x) 
{ 
    insert(end(), std::move(x)); 
} 

template<typename T> 
inline T & Deque<T>::popLeft() 
{ 
    return *begin(); erase(begin()); 
} 

template<typename T> 
inline T & Deque<T>::popRight() 
{ 
    return *end(); erase(end()); // changed --end to end 
} 

template<typename T> 
inline bool Deque<T>::contains(const T &) 
{ 
    // stuff here 
} 

template<typename T> 
inline Iterator Deque<T>::insert(Iterator itr, const T & x) 
{ 
    Node *p = itr.current; 
    theSize++; 
    return{ p->prev = p->prev->next = new Node{ x, p->prev, p } }; 
} 

template<typename T> 
inline Iterator Deque<T>::insert(Iterator itr, T && x) 
{ 
    Node *p = itr.current; 
    theSize++; 
    return{ p->prev = p->prev->next = new Node{ std::move(x), p->prev, p } }; 
} 

template<typename T> 
inline Iterator Deque<T>::erase(Iterator itr) 
{ 
    Node *p = itr.current; 
    Iterator retVal{ p->next }; 
    p->prev->next = p->next; 
    p->next->prev = p->prev; 
    delete p; 
    theSize--; 

    return retVal; 
} 

template<typename T> 
inline Iterator Deque<T>::erase(Iterator from, Iterator to) 
{ 
    for (Iterator itr = from; itr != to;) 
     itr = erase(itr); 

    return to; 
} 

template<typename T> 
inline void Deque<T>::init() 
{ 
    theSize = 0; 
    head = new Node; 
    tail = new Node; 
    head->next = tail; 
    tail->prev = head; 
} 

template<typename T> 
inline Deque<T>::Deque(const Deque & rhs) 
{ 
    init(); 
    *this = rhs; 
} 

#endif 
+0

Я также получаю ошибку: «Синтаксическая ошибка: ожидается» {'не'} '", но, похоже, не может найти отсутствующих скобок. Оба происходят по строке 135. –

+2

сообщение * минимальный * код - достаточно, чтобы воспроизвести проблему. –

+0

[связка других ошибок] (http://ideone.com/AfD5Os), но не «неожиданный конец найденного файла». –

ответ

0

Первая ошибка, чтобы исправить это один идентифицируются Альгирдас Preidžius: ваш конструктор имеет список инициализации, но не тело.

Вы должны заменить

Deque(Deque && rhs) : theSize{ rhs.theSize }, head{ rhs.head }, tail{ rhs.tail }; 

по

Deque(Deque && rhs) : theSize{ rhs.theSize }, head{ rhs.head }, tail{ rhs.tail } {}; 

Тогда вы будете иметь много других ошибок, чтобы исправить. Удачи !

Мой совет при кодировании: регулярно составляйте свой код, инсталлируйте, создавайте и проверяйте. У вас не должно быть так много ошибок, чтобы исправить сразу!

Кстати, почему бы не использовать std :: deque?

+0

Наш инструктор хотел, чтобы мы сделали это с нуля, иначе я бы это сделал. Благодаря! –

Смежные вопросы