The problem lies here:
delete first; first = first->next;
When you delete first
, but then try to access first->next
. Cache first->next
into a temp variable of type node*
, then do delete first
to fix this:
struct node* temp; while (first != NULL) { temp = first->next; delete first; first = temp; }
Related Posts:
- Writing a LinkedList destructor?
- Creating a copy constructor for a linked list
- How do I call the class’s destructor?
- std::out_of_range error?
- Debug assertion failed
- Destructor for Binary Search Tree
- member access within null pointer of type ‘struct ListNode’
- C++ Templates – LinkedList
- In C++ can constructor and destructor be inline functions?
- Destructor for a doubly-linked list that points to its value
- When is it safe to call this-> in constructor and destructor
- C++ Destructors with Vectors, Pointers,
- invalid use of template name without an argument list
- Array of Linked Lists C++
- How to throw a C++ exception
- The static keyword and its various uses in C++
- What is the ‘override’ keyword in C++ used for? [duplicate]
- Unresolved external symbol in object files
- Mutex example / tutorial? [closed]
- “std::bad_alloc”: am I using too much memory?
- What does “dereferencing” a pointer mean?
- What is a smart pointer and when should I use one?
- check if a std::vector contains a certain object?
- Convert char to int in C and C++
- How to convert a char array to a string?
- A proper way to create a matrix in c++
- No matching member function for call to ‘push_back’ error
- “X does not name a type” error in C++
- Difference between long double and double in C and C++ [duplicate]
- Why there is no pop_front method in C++ std::vector?
- How do I generate a random number between two variables that I have stored?
- How to print pthread_t
- make: g++: Command not found
- What is an ‘undeclared identifier’ error and how do I fix it?
- Use of “this” keyword in C++
- C++ error: “Array must be initialized with a brace enclosed initializer”
- Why am I getting string does not name a type Error?
- How to avoid the error: terminate called after throwing an instance of ‘std::logic_error’ what(): basic_string::_S_construct null not valid
- Error while overloading operator (must be a nonstatic member function)
- C++ Fatal Error LNK1120: 1 unresolved externals
- Vector of structs initialization
- C++ deprecated conversion from string constant to ‘char*’
- Converting a vector
to string - std::string formatting like sprintf
- Sorting Characters Of A C++ String
- C++ #include guards
- Is std::stoi actually safe to use?
- C++ forbids variable-size array
- Fill array with random numbers within a specified range (C++)
- Remove an array element and shift the remaining ones
- Right way to split an std::string into a vector
- string subscript out of range error
- push_back vs emplace_back
- No operator << matches these operands
- Returning an empty string : efficient way in c++
- How to find the size of an int[]?
- Append an int to a std::string
- Decimal to hex conversion c++ built-in function
- C++ IDE with repl?
- error: use of deleted function
- expected unqualified-id before string constant
- C++: Access violation writing location
- error: strcpy was not declared in this scope
- how to print a string to console in c++
- How to call a parent class function from derived class function?
- Error: No instance of constructor matches the argument list
- How can I get the list of files in a directory using C or C++?
- RPN Calculator for C++
- What does `Fatal Python error: PyThreadState_Get: no current thread` mean?
- Debug Assertion Failed: _CrtIsValidHeapPointer(block)
- gdb error not in executable format: File format not recognized
- C++ Erase vector element by value rather than by position?
- C++ Class ‘undeclared identifier”
- C++ – include unistd.h: why not cunistd?
- Dynamically allocated string array, then change it’s value?
- Use the auto keyword in C++ STL
- c++ –
- C++ – statement cannot resolve address for overloaded function
- What’s the difference between * and & in C?
- is there is a compiler which convert c++ code into mips assembly language
- term does not evaluate to a function taking 1 arguments
- reading from stdin in c++
- Stray ‘\342’ in C++ program
- gcc -g :what will happen
- QByteArray to QString
- Bitwise Less than or Equal to
- How to automatically convert strongly typed enum into int?
- Function cannot be referenced as it is a deleted function
- Understanding error “terminate called after throwing an instance of ‘std::length_error’ what(): basic_string::_S_create Aborted (core dumped)”
- how to find 2d array size in c++
- Getting error “array bound is not an integer constant before ‘]’ token”
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- error C2995: function template has already been defined
- Is there a way to compile C++ to C Code?
- enum to string in modern C++11 / C++14 / C++17 and future C++20
- Digit limitation from decimal point in C++
- error: expected unqualified-id before ‘while’|
- error C2039: ‘string’ : is not a member of ‘std’, header file problem
- allocating an object of abstract class type error
- “Cannot allocate an object of abstract type” error