I am "porting" a multiplatform project code from VS2003 to VS2013.
I hit an error that I cannot understand.
Here's a test code that illustrates it:
using namespace std;
class MyString : public string {
public:
MyString() : string() {};
MyString(const string &a_path) : string(a_path) {};
MyString(const MyString &a_path) : string(a_path) {};
friend MyString operator+(const MyString& path, const string& s) {
string str(path);
return str + s;
};
};
void test() {
MyString result;
MyString one;
result = one + string("aaa"); // error C2666 } }
This code can be compiled with VS2003 and several (newer) versions of gcc.
The VS2013 compiler complains with the following error:
1>mystring.cpp(22): error C2666: 'operator +' : 3 overloads have similar conversions
1>mystring.cpp(12): could be 'MyString operator +(const MyString &,const std::string &)' [found using argument-dependent lookup]
1> [...]\xstring(2411): or 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> std::operator +<char,std::char_traits<char>,std::allocator<char>>(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&)'
1> [...]\xstring(2401): or 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> std::operator +<char,std::char_traits<char>,std::allocator<char>>(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
1> [...]\xstring(2391): or 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> std::operator +<char,std::char_traits<char>,std::allocator<char>>(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&)'
1> [...]\xstring(2321): or 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> std::operator +<char,std::char_traits<char>,std::allocator<char>>(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
1> while trying to match the argument list '(MyString, std::basic_string<char,std::char_traits<char>,std::allocator<char>>)'
1> note: qualification adjustment (const/volatile) may be causing the ambiguity
The class in my project is one of basic classes and is used in whole project. So I am looking for a solution that would not affect a lot of code.