Skip to main content
added 207 characters in body
Source Link
yuri
  • 4.5k
  • 3
  • 19
  • 40
  • As others have already stated in the comments your program leaks memory because you never delete your list on destruction. Destructors will not magically clean things up for you. If you want something done then you need to do it yourself.
    I suggest taking another look at the basics. Perhaps this FAQ can help you. Also take a look at the official guidelines concerning resource managment. Generally the use of raw pointers is discouraged.

  • Node is an implementation detail and as such should be part of SingleLinkedList

  • Use member initialization lists or direct initialization

  • You are violating the rule of 3/5/0

  • Prefer using \n over std::endl

  • Prefer prefix over postfix

  • return 0 can be dropped from the end of main as it's optional

  • You are almost always using nullptr but then resort back to using NULL, why?

  • Your use of space after flow control statements is inconsistent and while not wrong it's really annoying to read

  • In your class the private keyword is redundant as everything in a class is private by default. Generally you should order your interface from public to private so people can read the public part first.

  • As others have already stated in the comments your program leaks memory because you never delete your list on destruction. Destructors will not magically clean things up for you. If you want something done then you need to do it yourself.
    I suggest taking another look at the basics. Perhaps this FAQ can help you. Also take a look at the official guidelines concerning resource managment. Generally the use of raw pointers is discouraged.

  • Node is an implementation detail and as such should be part of SingleLinkedList

  • Use member initialization lists or direct initialization

  • You are violating the rule of 3/5/0

  • Prefer using \n over std::endl

  • Prefer prefix over postfix

  • return 0 can be dropped from the end of main as it's optional

  • You are almost always using nullptr but then resort back to using NULL, why?

  • Your use of space after flow control statements is inconsistent and while not wrong it's really annoying to read

  • As others have already stated in the comments your program leaks memory because you never delete your list on destruction. Destructors will not magically clean things up for you. If you want something done then you need to do it yourself.
    I suggest taking another look at the basics. Perhaps this FAQ can help you. Also take a look at the official guidelines concerning resource managment. Generally the use of raw pointers is discouraged.

  • Node is an implementation detail and as such should be part of SingleLinkedList

  • Use member initialization lists or direct initialization

  • You are violating the rule of 3/5/0

  • Prefer using \n over std::endl

  • Prefer prefix over postfix

  • return 0 can be dropped from the end of main as it's optional

  • You are almost always using nullptr but then resort back to using NULL, why?

  • Your use of space after flow control statements is inconsistent and while not wrong it's really annoying to read

  • In your class the private keyword is redundant as everything in a class is private by default. Generally you should order your interface from public to private so people can read the public part first.

Source Link
yuri
  • 4.5k
  • 3
  • 19
  • 40

  • As others have already stated in the comments your program leaks memory because you never delete your list on destruction. Destructors will not magically clean things up for you. If you want something done then you need to do it yourself.
    I suggest taking another look at the basics. Perhaps this FAQ can help you. Also take a look at the official guidelines concerning resource managment. Generally the use of raw pointers is discouraged.

  • Node is an implementation detail and as such should be part of SingleLinkedList

  • Use member initialization lists or direct initialization

  • You are violating the rule of 3/5/0

  • Prefer using \n over std::endl

  • Prefer prefix over postfix

  • return 0 can be dropped from the end of main as it's optional

  • You are almost always using nullptr but then resort back to using NULL, why?

  • Your use of space after flow control statements is inconsistent and while not wrong it's really annoying to read