Debugger is giving me 'bad ptr' when I create a new string array in this constructor, but only when my overloading operator The method creates a new MyString object ... confused.
Here's my constructor
MyString :: MyString () {stringSize = 0; String cap = 16; String array = new four [string cap + 1]; Stringer [0] = '\ 0'; } This is my overloading operator method
Mystring Operator + (Const four * Left Op, Constant Mistine and Writeup) {MyStream Results; // New object results are used to store results. Striggies = Stellen (left option) + WINDOWS. String sequence; // if the string does not fit into the array (if result.stringSize> result.stringCap) {delete} string array; Result.stringCap = (result.stringSize + 15) & amp; ~ 15; Result.stringArray = New Four [result.stringCap + 1]; } Strcpy (result.stringArray, leftOp); Dome (result stringierae, writeup string strings); Return result; } This is my copy constructor, which never gets to the debugger
MyString :: MyString (const MyString & amp; s) {stringSize = S.stringSize; Stringcap = s.stringCap; // Stringer [StringCap + 1]; String array = new four [string cap + 1]; Stringaray = s.stringArray; }
There is nothing wrong with your code snippet, my sixth sense tells me That you have not written copy-constructor, and are working with the default generated by the compiler, or maybe stringArray is not a redundant string! Edit:
In your copy-constructor, this is incorrect:
stringArray = s.stringArray; //wrong! Instead of using strcpy : strcpy (stringArray, s.stringArray); //correct! Make sure all your strings are meaningless!
Comments
Post a Comment