/* CONSTRUCTOR */
GString(constchar* CstyleString)
{
// +1 for the NULL character at the end (/0)
size = strlen(CstyleString) + 1;
mainString = newchar[size];
int i = 0;
// -1 because we want to set the NULL character AFTER the copy of the character from one vector to another
for (i = 0; i < size - 1; i++)
mainString[i] = CstyleString[i];
mainString[i] = '\0';
}
/* OPERATOR OVERLOADING */
charoperator[](int Index)
{
if (Index >= 0 && Index < size)
return mainString[Index];
}
constcharoperator[](int Index) const
{
if (Index >= 0 && Index < size)
return mainString[Index];
}
GString& operator=(const GString& other)
{
size = other.size;
delete[] mainString;
mainString = newchar[size];
for (int i = 0; i < size; i++)
{
mainString[i] = other.mainString[i];
}
return *this;
}
Any tip?
P.S: I KNOW what is a lvalue and a rvalue, but I think there's a bug in the operator overloading...