C++ overloading += operator with double pointers -


so i'm trying overload += operator dictionary program assignment. function:

definition& definition::operator += (const string& input) {     string** temp;     temp = new string*[numdefs + 1];     temp[0] = new string[numdefs];     (int = 0; < numdefs; i++)   {             temp[i] = def[i];     }     temp[0][numdefs] = input;     delete[] def;     def = temp;     numdefs++;     return *this; } 

however when try put 'input' 'temp' doesn't seem work. string class function allocating string string:

string& string::operator=(const string& input) {     data = null;     (*this) = input.getdata();     return *this; } 

and:

string& string::operator=(const char* input) {     if (data != input)     {         if (data != null)         {             delete[] data;             data = null;         }         data_len = strsize(input);         if (input != null)         {             data = new char[data_len + 1];             strcopy(data, input);         }     }     return *this; } 

can't seem find problem.

there answer posted minute ago user deleted , helped me, changed code to:

definition& definition::operator += (const string& input) {     string** temp;     int tempsize = numdefs + 1;     temp = new string*[tempsize];     (int = 0; < numdefs; i++)   {         temp[i] = new string;         temp[i] = def[i];     }     temp[numdefs] = new string;     (*temp[numdefs]) = input;     delete[] def;     def = temp;     numdefs = tempsize;     return *this; } 

whoever was, thanks!


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -