fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class t>
  5.  
  6. static class node{
  7. t value;
  8. node* next;
  9.  
  10. node (t value){
  11. this->value=value;
  12. next = nullptr;
  13. }
  14.  
  15.  
  16. };
  17.  
  18. template <class t>
  19.  
  20. class linkedList{
  21. node<t>* head; int size;
  22. int Size (){
  23. return size;
  24. }
  25.  
  26. public:
  27. void push_front(t value){
  28.  
  29. node<t> *newnode;
  30. newnode = new node<t>(value);
  31. if(size==0){
  32. head=newnode; size++;
  33. } else {
  34. newnode->next=head;
  35. head=newnode;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. }
  42. void push_back(t value){
  43. if(size==0){
  44. push_front(value);
  45. }else {
  46. node<t> current=head;
  47. while (current.next !=value){
  48. current =current.next;
  49. }
  50. node<t> newnode = new node<t>(value);
  51. current.next =newnode;
  52. size++;
  53.  
  54. }
  55.  
  56.  
  57. }
  58. void traverse(){
  59. node<t> current =head;
  60. while (current != nullptr){
  61. cout<<current.value <<" ";
  62. current =current.next;
  63. }
  64.  
  65. }
  66.  
  67.  
  68. linkedList(){
  69. size=0;
  70. head= nullptr;
  71. }
  72. };
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. int main() {
  86.  
  87.  
  88. linkedList<int> l;
  89.  
  90. l.push_front(5);
  91. l.push_front(10);
  92. l.push_front(5);
  93. l.push_front(10);
  94. l.push_front(5);
  95. l.push_front(10);
  96. l.push_front(5);
  97. l.push_front(10);
  98. l.traverse();
  99. return 0;
  100. }
  101.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:2: error: a storage class can only be specified for objects and functions
  static class node{
  ^~~~~~
prog.cpp: In instantiation of ‘void linkedList<t>::push_front(t) [with t = int]’:
prog.cpp:90:15:   required from here
prog.cpp:30:19: error: ‘node<t>::node(t) [with t = int]’ is private within this context
         newnode = new node<t>(value);
                   ^~~~~~~~~~~~~~~~~~
prog.cpp:10:5: note: declared private here
     node (t value){
     ^~~~
prog.cpp:34:22: error: ‘node<int>* node<int>::next’ is private within this context
             newnode->next=head;
             ~~~~~~~~~^~~~
prog.cpp:8:11: note: declared private here
     node* next;
           ^~~~
prog.cpp: In instantiation of ‘void linkedList<t>::traverse() [with t = int]’:
prog.cpp:98:16:   required from here
prog.cpp:59:17: error: ‘node<t>::node(t) [with t = int]’ is private within this context
         node<t> current =head;
                 ^~~~~~~
prog.cpp:10:5: note: declared private here
     node (t value){
     ^~~~
prog.cpp:59:26: error: invalid conversion from ‘node<int>*’ to ‘int’ [-fpermissive]
         node<t> current =head;
                          ^~~~
prog.cpp:10:13: note:   initializing argument 1 of ‘node<t>::node(t) [with t = int]’
     node (t value){
           ~~^~~~~
prog.cpp:60:24: error: no match for ‘operator!=’ (operand types are ‘node<int>’ and ‘std::nullptr_t’)
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/iosfwd:40,
                 from /usr/include/c++/8/ios:38,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/postypes.h:221:5: note: candidate: ‘template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)’
     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
     ^~~~~~~~
/usr/include/c++/8/bits/postypes.h:221:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::fpos<_StateT>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:64,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stl_pair.h:461:5: note: candidate: ‘template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)’
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
/usr/include/c++/8/bits/stl_pair.h:461:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::pair<_T1, _T2>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stl_iterator.h:314:5: note: candidate: ‘template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)’
     operator!=(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:314:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stl_iterator.h:352:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)’
     operator!=(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:352:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stl_iterator.h:1127:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)’
     operator!=(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:1127:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::move_iterator<_IteratorL>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/bits/char_traits.h:39,
                 from /usr/include/c++/8/ios:40,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stl_iterator.h:1133:5: note: candidate: ‘template<class _Iterator> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)’
     operator!=(const move_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:1133:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::move_iterator<_IteratorL>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/string:41,
                 from /usr/include/c++/8/bits/locale_classes.h:40,
                 from /usr/include/c++/8/bits/ios_base.h:41,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/allocator.h:158:5: note: candidate: ‘template<class _T1, class _T2> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_T2>&)’
     operator!=(const allocator<_T1>&, const allocator<_T2>&)
     ^~~~~~~~
/usr/include/c++/8/bits/allocator.h:158:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::allocator<_CharT>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/string:41,
                 from /usr/include/c++/8/bits/locale_classes.h:40,
                 from /usr/include/c++/8/bits/ios_base.h:41,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/allocator.h:164:5: note: candidate: ‘template<class _Tp> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_CharT>&)’
     operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
     ^~~~~~~~
/usr/include/c++/8/bits/allocator.h:164:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::allocator<_CharT>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
                 from /usr/include/c++/8/bits/locale_classes.h:40,
                 from /usr/include/c++/8/bits/ios_base.h:41,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/basic_string.h:6095:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/8/bits/basic_string.h:6095:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
                 from /usr/include/c++/8/bits/locale_classes.h:40,
                 from /usr/include/c++/8/bits/ios_base.h:41,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/basic_string.h:6108:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
     operator!=(const _CharT* __lhs,
     ^~~~~~~~
/usr/include/c++/8/bits/basic_string.h:6108:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   mismatched types ‘const _CharT*’ and ‘node<int>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
                 from /usr/include/c++/8/bits/locale_classes.h:40,
                 from /usr/include/c++/8/bits/ios_base.h:41,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/basic_string.h:6120:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)’
     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/8/bits/basic_string.h:6120:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/8/bits/ios_base.h:46,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/system_error:319:3: note: candidate: ‘bool std::operator!=(const std::error_code&, const std::error_code&)’
   operator!=(const error_code& __lhs, const error_code& __rhs) noexcept
   ^~~~~~~~
/usr/include/c++/8/system_error:319:3: note:   no known conversion for argument 1 from ‘node<int>’ to ‘const std::error_code&’
/usr/include/c++/8/system_error:323:3: note: candidate: ‘bool std::operator!=(const std::error_code&, const std::error_condition&)’
   operator!=(const error_code& __lhs, const error_condition& __rhs) noexcept
   ^~~~~~~~
/usr/include/c++/8/system_error:323:3: note:   no known conversion for argument 1 from ‘node<int>’ to ‘const std::error_code&’
/usr/include/c++/8/system_error:327:3: note: candidate: ‘bool std::operator!=(const std::error_condition&, const std::error_code&)’
   operator!=(const error_condition& __lhs, const error_code& __rhs) noexcept
   ^~~~~~~~
/usr/include/c++/8/system_error:327:3: note:   no known conversion for argument 1 from ‘node<int>’ to ‘const std::error_condition&’
/usr/include/c++/8/system_error:331:3: note: candidate: ‘bool std::operator!=(const std::error_condition&, const std::error_condition&)’
   operator!=(const error_condition& __lhs,
   ^~~~~~~~
/usr/include/c++/8/system_error:331:3: note:   no known conversion for argument 1 from ‘node<int>’ to ‘const std::error_condition&’
In file included from /usr/include/c++/8/bits/locale_facets.h:48,
                 from /usr/include/c++/8/bits/basic_ios.h:37,
                 from /usr/include/c++/8/ios:44,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/streambuf_iterator.h:209:5: note: candidate: ‘template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)’
     operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
     ^~~~~~~~
/usr/include/c++/8/bits/streambuf_iterator.h:209:5: note:   template argument deduction/substitution failed:
prog.cpp:60:24: note:   ‘node<int>’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
         while (current != nullptr){
                ~~~~~~~~^~~~~~~~~~
prog.cpp:61:27: error: ‘int node<int>::value’ is private within this context
             cout<<current.value <<"  ";
                   ~~~~~~~~^~~~~
prog.cpp:7:7: note: declared private here
     t value;
       ^~~~~
prog.cpp:62:30: error: ‘node<int>* node<int>::next’ is private within this context
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:8:11: note: declared private here
     node* next;
           ^~~~
prog.cpp:62:21: error: ambiguous overload for ‘operator=’ (operand types are ‘node<int>’ and ‘node<int>*’)
             current =current.next;
             ~~~~~~~~^~~~~~~~~~~~~
prog.cpp:6:15: note: candidate: ‘constexpr node<int>& node<int>::operator=(const node<int>&)’ <near match>
  static class node{
               ^~~~
prog.cpp:6:15: note:   conversion of argument 1 would be ill-formed:
prog.cpp:62:30: error: invalid user-defined conversion from ‘node<int>*’ to ‘const node<int>&’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:10:5: note: candidate is: ‘node<t>::node(t) [with t = int]’ <near match>
     node (t value){
     ^~~~
prog.cpp:10:5: note:   conversion of argument 1 would be ill-formed:
prog.cpp:62:30: error: invalid conversion from ‘node<int>*’ to ‘int’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:62:21: error: ‘node<t>::node(t) [with t = int]’ is private within this context
             current =current.next;
             ~~~~~~~~^~~~~~~~~~~~~
prog.cpp:10:5: note: declared private here
     node (t value){
     ^~~~
prog.cpp:62:30: error: invalid conversion from ‘node<int>*’ to ‘int’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:10:13: note:   initializing argument 1 of ‘node<t>::node(t) [with t = int]’
     node (t value){
           ~~^~~~~
prog.cpp:6:15: note: candidate: ‘constexpr node<int>& node<int>::operator=(node<int>&&)’ <near match>
  static class node{
               ^~~~
prog.cpp:6:15: note:   conversion of argument 1 would be ill-formed:
prog.cpp:62:30: error: invalid user-defined conversion from ‘node<int>*’ to ‘node<int>&&’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:10:5: note: candidate is: ‘node<t>::node(t) [with t = int]’ <near match>
     node (t value){
     ^~~~
prog.cpp:10:5: note:   conversion of argument 1 would be ill-formed:
prog.cpp:62:30: error: invalid conversion from ‘node<int>*’ to ‘int’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:62:21: error: ‘node<t>::node(t) [with t = int]’ is private within this context
             current =current.next;
             ~~~~~~~~^~~~~~~~~~~~~
prog.cpp:10:5: note: declared private here
     node (t value){
     ^~~~
prog.cpp:62:30: error: invalid conversion from ‘node<int>*’ to ‘int’ [-fpermissive]
             current =current.next;
                      ~~~~~~~~^~~~
prog.cpp:10:13: note:   initializing argument 1 of ‘node<t>::node(t) [with t = int]’
     node (t value){
           ~~^~~~~
prog.cpp:62:21: error: conversion to non-const reference type ‘class node<int>&&’ from rvalue of type ‘node<int>’ [-fpermissive]
             current =current.next;
             ~~~~~~~~^~~~~~~~~~~~~
stdout
Standard output is empty