Problems with first argument being string when overloading the + operator in C++
- by Chris_45
I have an selfmade Stringclass:
//String.h
String & operator = (const String &);
String & operator = (char*);
const String operator+ (String& s);
const String operator+ (char* sA);
.
.
//in main:
String s1("hi");
String s2("hello");
str2 = str1 + "ok";//this is ok to do
str2 = "ok" + str1;//but not this way
//Shouldn't it automatically detect that one argument is a string and in both cases?