Hi,
im trying to overload the "+" operator to join 3 strings together, but im having difficulty. Im only doing this for a bit of experimentation.
CStr String1 = "Part1";
CStr String2 = "Part2\n";
CStr String3;
String3 = String1 + " " + String2;
// This works...
//String3.operator+(String1);
//String3.operator+(" "
;
//String3.operator+(String2);
printf(String3);
CStr:
perator char*()
{
return _str;
}
CStr& CStr:
perator=(const char* String)
{
this->Copy(String);
return *this;
}
CStr& CStr:
perator+(const char* String)
{
this->Join(String);
return *this;
}
However, this is bad because, when using the "+" operator, like this:
CStr String1 = "Part1";
CStr String2 = "Part2\n";
CStr String3;
String3 = String1 + " " + String2;
String1 ends up with the value of "Part1 ", instead of "Part1". And also the program crashes when the classes are deleted because it automatically frees the memory. but because of the return *this, its messing up.
Anyone got any pointers for this kind of thing?
cheers
Skute
"There are 10 types of people in this World, those that understand binary, and those that don't!"
im trying to overload the "+" operator to join 3 strings together, but im having difficulty. Im only doing this for a bit of experimentation.
CStr String1 = "Part1";
CStr String2 = "Part2\n";
CStr String3;
String3 = String1 + " " + String2;
// This works...
//String3.operator+(String1);
//String3.operator+(" "
//String3.operator+(String2);
printf(String3);
CStr:
{
return _str;
}
CStr& CStr:
{
this->Copy(String);
return *this;
}
CStr& CStr:
{
this->Join(String);
return *this;
}
However, this is bad because, when using the "+" operator, like this:
CStr String1 = "Part1";
CStr String2 = "Part2\n";
CStr String3;
String3 = String1 + " " + String2;
String1 ends up with the value of "Part1 ", instead of "Part1". And also the program crashes when the classes are deleted because it automatically frees the memory. but because of the return *this, its messing up.
Anyone got any pointers for this kind of thing?
cheers
Skute
"There are 10 types of people in this World, those that understand binary, and those that don't!"