类模板错误,链接列表

时间:2017-01-03 16:45:24

标签: c++ class c++11 linked-list

我正在尝试创建一个无序的链表,我正在使用的教科书说在创建链表ADT之前需要一个链表迭代器类。最终它将是一个功能链表,可以反向打印,在节点分割并与另一个节点合并。我只启动了链接的List迭代器类,代码已经从文本中复制,但是没有构建。我认为这是一个标题/前进声明问题,但我已经尝试过,但仍然没有。有什么想法吗?

//。h file - linkedListIterator.h

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstddef>

using namespace std;

#ifndef LINKEDLISTITERATOR_H
#define LINKEDLISTITERATOR_H

template <class Type>
class linkedListIterator
{
    public:
        //Default COnstructor
        linkedListIterator();

    //Constructor with parameter, *curretn = *ptr
    linkedListIterator(nodeType<Type> *ptr);

    //overload deref operator - return info in node
    Type operator*();

    //Overlaod pre inc operator - adv iterator to next node
    linkedListIterator<Type> operator++;

    //Overload equlaity operator - return true if iterator is eq to iter on right
    bool operator==(const linkedListIterator<Type>& right) const;

    //Overload not equal to operator- return true iter is not eq to iter on right
    bool operator!=(const linkedListIterator<Type>& right) const;

private:
    //ptr to current node in linked list
    nodeType<Type> *current;
};

#endif

//。cpp文件 - linkedListIterator.cpp

#include "stdafx.h"
#include "linkedListIterator.h"

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstddef>

using namespace std;

template <class Type>
linkedListIterator<Type>::linkedListIterator()
{
    current = nullptr;
}

template <class Type>
linkedListIterator<Type>::linkedListIterator(nodeType<Type> *ptr)
{
    current = ptr;
}

template <class Type>
Type linkedListIterator::operator*()
{
    return current->info;
}

template <class Type>
linkedListIterator<Type> linkedListIterator<Type>::operator++()
{
   current = current->link;
   return *this;
}

template <class Type>
bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>& right) const
{
    return (current == right.current);
}

template <class Type>
bool linkedListIterator<Type>::operator==(const linkedListIterator<Type>& right) const
{
    return (current != right.current);
}

//主文件 - CH16_Q4Q6Q7_OrderedandUnordered.cpp
     / 还没有 /

#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstddef>

using namespace std;

int main()
{
    return 0;
}

我收到错误 C2061 - 语法错误:标识符'nodeType'
C2535 - 'linkedListIterator :: linkedListIterator(void)':已定义或声明的成员函数'
C2143 - 语法错误:缺少';'在'&lt;'之前 C4430 - 缺少类型说明符 - 假设为int。注意C ++不支持default-int
C2238 - ';'之前的意外标记 C2988 - 无法识别的模板声明/定义
C2059 - 语法错误'('
C2649 - 'typename':不是'类' C1004 - 发现意外的文件结尾

0 个答案:

没有答案
相关问题