Can someone tell me why when my split function runs it makes the list2 of the object lst2 read "Error reading characters of string"
LinkedDeque* LinkedDeque::split()
{
LinkedDeque* lst2 = new LinkedDeque();
DLinkedList list2 = *(D.split());
lst2->list2 = list2;
return lst2;
}
void LinkedDeque::print() {
D.print();
}
void LinkedDeque::splitprint() {
list2.print();
}
int main()
{
LinkedDeque list;
while (true)
{
string x;
cout << "Enter a non-negative number (Negative number to end): ";
cin >> x;
cout << endl;
if (stoi(x) < 0)
break;
list.insertFront(x);
}
cout << "Entries Given:\n";
list.print();
cout << "Splitting the given list ...\n";
LinkedDeque lst2 = *(list.split());
cout << "\n1st Split List : \n";
list.print();
cout << "2nd Split List : \n";
lst2.splitprint();
return EXIT_SUCCESS;
}
If more code is needed to tell me why this is going on I can provide the full code of the program I am working on. I am clearly not the best at programing so please explain it so I can understand. I have been working on this for 3 days now and cannot figure out why this is happening.