c++ - Overloading + to add two pointers -


I have a string class and I want to overload to add two string * pointers: Something does not work like this:

  string * operator + (string * s1, string * s2);  

What is the way to avoid going through the context? Consider this example:

  string * s1 = new string ("hello"); String * s2 = new string ("world"); String * s3 = s1 + s2;  

I have an additional requirement for this type of work. Please suggest.

You can not do that you can not overload the operator for the underlying types. In any case, why use the indicator? Avoid as much dynamic allocation as possible!

  string s1 ("hello"); String S2 ("World"); String s3 = s1 + s2;  

It is much better, and does not leak. You can now overload:

  string operator + (const string and s1, const string and s2);  

How do you wish it is definitely a waste of time, because std :: string exists :)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -