-
April 17th, 2011, 05:38 PM
#1
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);
Last edited by rjs123; April 17th, 2011 at 05:44 PM.
-
April 17th, 2011, 07:22 PM
#2
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 +=
-
April 18th, 2011, 02:31 AM
#3
Re: error: overloads have similar conversions
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)
-
April 18th, 2011, 03:59 AM
#4
Re: error: overloads have similar conversions
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|