c++ - Heap Corruption Detected -


The only thing wrong about the output of my program is that one '!' After 'fishing' I have tried to debug it but never '!' in the memory of.

The output of this line is here

  Another: went down to the fishing! Holes   

Here is the creation of S6 and S7

  MyString s6 ("gone"); Mystring S 7 ("Fishing");   

Here is the line that produces the statement

  cout & lt; & Lt; "One more:" & lt; & Lt; Below S6 + "+ +" + s7 + "hole" & lt; & Lt; Andal & lt; & Lt; Endl;   

here & lt; & Lt; Operator Overload function

  Ostream & amp; Operator & lt; & Lt; (Ostream and BoveOp, Const Maestring and Writeop) {leftOp & lt; & Lt; RightOp.stringArray; Return left; }   

Here is the operator overload function

  Maestration Maestroeng :: Operator + (Const four * writeup) const {MyString result; // New object results are used to store results. String = Signal = String + strollon (writeup); // if the string does not fit into the array (if result.stringSize> result.stringCap) {delete} string array; Result.stringCap = (string size + 15) & amp; ~ 15; Result.stringArray = New Four [StringCap + 1]; } Strcpy (result.stringArray, stringArray); Dome (result. Stringer, Write); Return result; }   

S7 is not called anywhere in the program so I think that there is no code that should be shown now. Any help will be very much appreciated.

It is difficult to say if there is a problem with your code here - I see other members Will have followed the rules of 3 ?

Note:

I tell you that you are breaking a fundamental OO rule.

You should not fiddle with members of any other object, unless is very good

  maststring migration :: operator (Const char * rightOp) const {MyString} If you type it, the code will be cleared:  result (* this); // Make a copy of this result + = rightOp; // Get the result of Bella here with your own members. Return result; }   

Edit:

Based on the comment below. Actually: If your object is dynamic owner of allocated memory (i.e. this new call / deletes), then the default version of the methods generated by the compiler does not work as intended. ; And you should define your own versions:

Basically:

  * Copy Constructor * Assignment Operator * is not a part of the District * 3 rule, but You might be a general producer.   

The simple thing is that maybe you are already a destroyer (otherwise corruption will not happen), and the assignment operator can be written in the context of copy constructor, so all you need to do is It should write a correct version of the copy constructor and everything should work.

  / * * Assignment operator using Copy and Swap IDEAP * Copy Copy uses Constructor (here the value is crossed) * * Then you just copy the current content * / MyStruth & amp; MyString :: Operator = (Mystring rhs) {(* This). Swap (ras); Return * This; }    

Comments