Semantically, the equivalent of your Python code will be something like
std::string x = "wow"; x + x;
i.e. create a temporary string that is a concatenation of x with x and will discard the result. To add to x , you must do the following:
std::string x = "wow"; x += x;
Note double quotes. " Unlike python, in C ++, single quotes for single characters and double quotes for null-terminated string literals.
See the std::string link.
By the way, in Python, you usually do not call the __add__() method. You would use the equivalent syntax for the first C ++ example:
x = 'wow' x + x
The __add__() method is just a python way to provide a plus operator for a class.
juanchopanza
source share