Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #ifndef S_LINKED_LIST
  2. #define S_LINKED_LIST
  3.  
  4. template <typename E>
  5. class SLinkedList;
  6.  
  7. template <typename E>
  8. class SNode
  9. {
  10. private:
  11. E elem;
  12. SNode<E> * next;
  13. friend class SLinkedList<E>;
  14. };
  15. template <typename E>
  16. class SLinkedList
  17. {
  18. private:
  19. SNode<E> * head;
  20. public:
  21. SLinkedList();
  22. ~SLinkedList();
  23. bool empty() const;
  24. const E& front() const;
  25. void addFront(const E& e);
  26. void removeFront();
  27. };
  28. #endif /*SLinkedList.h*/
  29.  
  30. #include "SLinkedList.h"
  31. #include <iostream>
  32.  
  33. template <typename E>
  34. SLinkedList<E>::SLinkedList():head(NULL){}
  35.  
  36. template <typename E>
  37. SLinkedList<E>::~SLinkedList()
  38. {while(!empty()) removeFront();}
  39.  
  40. template <typename E>
  41. bool SLinkedList<E>::empty() const
  42. {return head == NULL;}
  43.  
  44. template <typename E>
  45. const E& SLinkedList<E>::front() const
  46. {return head->elem;}
  47.  
  48. template <typename E>
  49. void SLinkedList<E>::addFront(const E& e)
  50. {
  51. SNode<E> * newNode = new SNode<E>;
  52. newNode->elem = e;
  53. newNode->next = head;
  54. head = newNode;
  55. }
  56.  
  57. template <typename E>
  58. void SLinkedList<E>::removeFront()
  59. {
  60. SNode<E> * old = head;
  61. head = old->next;
  62. delete old;
  63. }/*SLinkedList.cpp*/
  64.  
  65. #include <iostream>
  66. #include "SLinkedList.h"
  67.  
  68. int main()
  69. {
  70. SLinkedList<std::string> newlist;
  71. newlist.addFront("MSP");
  72. std::cout << newlist.front();
  73. return 0;
  74. }/*test_slinkedlist.cpp*/
  75.  
  76. Undefined symbols for architecture x86_64:
  77. ...
  78. ld: symbol(s) not found for architecture x86_64
  79. clang: error: linker command failed with exit code 1 (use -v to see invocation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement