I'm am working on a string class. Each character of the string occupies one node. The function that my string class uses to convert from char * to string (the name of my string class) is giving me problems. Because my code is fairly short still, I will post all of it:
The problem occurs on, guess where, the line that has the comment "the problem". I have no idea why I get an unhandled exception message because of this line. Any help anyone can give would be very much appreciated.Code:#include <iostream> using std::cout; using std::cin; using std::endl; class string { protected: struct node { node * next; char c; node() : next(0) {} }; node * head; node * current; public: string(); string(char *); string & operator=(string &); }; string::string() { head = new node; current = head; } string::string(char * str) { current = head; unsigned int a = 0; while(str[a] != '\0') { if (current == 0) current = new node; /*the problem*/current->c = str[a]; cout << current->c << endl; a++; current = current->next; } } string & string::operator=(string & s) { s.current = s.head; current = head; while (s.current != 0) { if (current == 0) current = new node; current->c = s.current->c; s.current = s.current->next; current = current->next; } if (current->next != 0) { current = current->next; while (current != 0) { delete current; current = current->next; } } } int main() { string test = "fart"; return 0; }