I've been working on this string class for a while now, and I just tried to compile its test file again. My program crashed, so I said "Well, alright, let's look at the assignment operator overload." Looking over it, I see nothing wrong. Finally, I decided to put the code into a project and run the debugger. Once the debugger started, the program ran and exited normally! WTF? Here's my code:
#include <cstdio>
#include "string.h"
int main(){
string str;
str="Merry Christmas to you!";
//tests show that it crashed here vvv
str.replace("Christmas","Hanukkah");
printf("String: %s\nUpper: %s\nLower: %s\n",str.c_str(),str.upper().c_str(),str.lower().c_str());
getchar();
return 0;}
Why shouldn't I switch characters using an XOR swap?
EDIT: Strange thing, I added a few functions and it started working...
EDIT2: Scratch that, it was just because I used printf("DEBUG") before anything else... Weird stuff.
Double check all your pointers, arrays, etc. If you add or remove random stuff that isn't related and suddenly the code works (or doesn't), then it is most likely memory corruption.
string::resizedata is quite confusing. the parameter newsize is not going to be the size of the string, but the number of cells added.
so you end with constructions like this: resizedata(s<<1-datasize). (that is funny, you are trying to optimize a multiplication but you do an unnecessary memcopy) resizedata(((size2-size1)*c)<<1);
I think that countstr could be incorrect (pos should be reset on a mismatch)