error: overloads have similar conversions
I have these overload functions which take different parameters...and basically concatenate two strings together except for the first declaration. The error that arises is c2666 which basically says that they have similar conversions...any ideas on fixing this?
Code:
String& operator+(const String& s);
friend String operator+(const String& s, const String& t);
friend String operator+(const String& s, const char* t);
friend String operator+(const char* s, const String& t);
friend String operator+(const String& s, char t);
friend String operator+(char s, const String& t);
Re: error: overloads have similar conversions
Can you provide a complete code that demonstrates the error ? I created
a small program with your code and did not have any compile errors
with VC2010 or Comeau.
One thing you should change, you have a member function and
non member function to add two Strings
Code:
String& operator+(const String& s)
friend String operator+(const String& s, const String& t);
1) operator + should return a "String" not a "String&"
2) change the member function to operator += (which does
return a reference ... *this). Then you code operator +
in terms of operator +=
Re: error: overloads have similar conversions
Quote:
Originally Posted by
Philip Nicoletti
Can you provide a complete code that demonstrates the error ? I created
a small program with your code and did not have any compile errors
with VC2010 or Comeau.
One thing you should change, you have a member function and
non member function to add two Strings
Code:
String& operator+(const String& s)
friend String operator+(const String& s, const String& t);
1) operator + should return a "String" not a "String&"
2) change the member function to operator += (which does
return a reference ... *this). Then you code operator +
in terms of operator +=
after looking at my declarations...i had an additional function that should not have been there...probably occurred from copying and pasting.
I have one more error to solve...and it is not related to the code...any suggestions?
Code:
Strdrv.obj : error LNK2019: unresolved external symbol "public: __thiscall ReverseString::~ReverseString(void)" (??1ReverseString@@QAE@XZ) referenced in function "void __cdecl test19(void)" (?test19@@YAXXZ)
Re: error: overloads have similar conversions
Quote:
Originally Posted by
rjs123
after looking at my declarations...i had an additional function that should not have been there...probably occurred from copying and pasting.
I have one more error to solve...and it is not related to the code...any suggestions?
Code:
Strdrv.obj : error LNK2019: unresolved external symbol "public: __thiscall ReverseString::~ReverseString(void)" (??1ReverseString@@QAE@XZ) referenced in function "void __cdecl test19(void)" (?test19@@YAXXZ)
You did not implement the destructor for ReverseString.
Regards,
Paul McKenzie