I have written a simple C++ program to implement the string class. This class has member functions for +operator and =operator overload in addition to the constructors that I have defined for it.
The program runs but it stops with an error message saying "windows has triggered a break point in my program.This may be due to the corruption of the heap which indicated a bug in the program or the dlls that it loads"
The program produces correct output but it stops before returning the handle to the OS. I would appreciate it if somebody could help me ..
One problem is operator +. concatedSTR never points to anything. Though in fact, it shouldn't be a pointer at all. If you allocated memory, you'd never delete it. Its fine to return by value.
I changed the return type of the operator+ function.So now it returns an object of the MyCString class type and no pointer. I figured out that the function perfectly runs as if I print out the concatedSTR in the function in has concatenated the two stings. But it never returns to the main program after and so it doesn't run the next line in main program which is st5.showSTR();
A problem in operator =. You wrote () instead of []. Now only one char is allocated.
Also, you're misusing strcat. It appends the 2nd string to the 1st one and the result is stored in 1st. You should first copy the 1st string with strcpy and then use strcat.