Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 18th, 2012  |  syntax: None  |  size: 2.14 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. error: expected unqualified-id before '<' token (Template compilation issue)
  2. typedef <typename ListType>
  3.        
  4. #if !defined _LIST_HPP_
  5. #define _LIST_HPP_
  6.  
  7. #include "Node.hpp"
  8.  
  9. ///since we're creating a template everything must be defined in the hpp
  10.  
  11. typedef <typename ListType>
  12. class List
  13. {
  14.    public:
  15.       List();
  16.       bool Empty();
  17.       void PushFront();
  18.       void PushBack();
  19.       void PopBack();
  20.       Node<ListType>& GetHead();
  21.  
  22.    private:
  23.       int _size;
  24.       Node<ListType>* _head;
  25.       Node<ListType>* _tail;
  26. };
  27.  
  28.  
  29. ///implement List class here
  30. typedef <typename ListType>
  31. List<ListType>::List() : _head(0), _tail(0), _size(0)
  32. {
  33. }
  34. typedef <typename ListType>
  35. bool <ListType>Empty()
  36. {
  37.    return !_size; //returns true if size = 0
  38. }
  39. typedef <typename ListType>
  40. void List<ListType>::PushFront()
  41. {
  42.    _head = new Node<ListType>( _head , 0 );
  43.    if (!Empty())
  44.       _head->_prev->_next = _head; //set previous nodes _next to new _head
  45.  
  46.    ++_size;
  47. }
  48. typedef <typename ListType>
  49. void List<ListType>::PushBack()
  50. {
  51.    _tail = new Node<ListType>( 0 , _tail);
  52.    if (!Empty())
  53.       _tail->_next->_prev = _tail; // set old tails _prev to new tail
  54.  
  55.    ++_size;
  56. }
  57. typedef <typename ListType>
  58. void List<ListType>::PopBack()
  59. {
  60.  
  61. }
  62. typedef <typename ListType>
  63. Node<ListType>& List<ListType>::GetHead()
  64. {
  65.    return _head;
  66. }
  67.  
  68. #endif //define
  69.        
  70. #if !defined _NODE_HPP_
  71. #define _NODE_HPP_
  72.  
  73.  
  74. //#include "Sprite.hpp"
  75.  
  76. template<typename NodeType>
  77. class Node{
  78.    public:
  79.       Node( Node* prev = 0, Node* next = 0);
  80.       void SetData(NodeType newData);
  81.       void GetData();
  82.    private:
  83.       friend class List;
  84.  
  85.       NodeType _data;
  86.       Node* _next;
  87.       Node* _prev;
  88.  
  89. };
  90.  
  91.  
  92. ///implement Node
  93.  
  94. template <typename NodeType>
  95. Node<NodeType>::Node(Node* prev, Node* next) : _prev(prev), _next(next)
  96. {}
  97. template <typename NodeType>
  98. void Node<NodeType>::SetData(NodeType newData)
  99. {
  100.    _data = newData;
  101. }
  102. template <typename NodeType>
  103. void Node<NodeType>::GetData()
  104. {
  105.    return _data;
  106. }
  107.  
  108. #endif //define
  109.        
  110. typedef <typename ListType>
  111. bool <ListType>Empty()
  112. {
  113.    return !_size; //returns true if size = 0
  114. }
  115.        
  116. template <typename ListType>
  117. bool List<ListType>::Empty()
  118. {
  119.     return _size != 0;
  120. }