I'm learning C++ and creating a simple class, tstring
, defined by:
n
the number of characters in a string;ntotal
the total number of characters in the tstring;p
, pointer to a zone which contains the data.
Hence, this class is composed by a static part (n
, ntotal
and p
) and by a dynamic part (the data itself).
I created three constructors :
- one without parameters;
- one copy constructor;
- one constructor which takes a C-string parameter.
I would like to be able to concatenate one tstring
object with one C string, using for example the instructions :
tstring x("Hello), y;
y = x + " World";
I think I should overload the +
operator. However I don't understand which way I should use to overload it between internal way :
tstring tstring::operator+(char string[])
or external way (with setter and getter methods)
tstring operator+ (const tstring& myTstring, const char* string)
Can someone explain me the difference and the best way to adopt?
Thank you in advance!