error: overloads have similar conversions
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: error: overloads have similar conversions

  1. #1
    Join Date
    Feb 2011
    Posts
    54

    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 06:44 PM.

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,646

    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 +=

  3. #3
    Join Date
    Feb 2011
    Posts
    54

    Re: error: overloads have similar conversions

    Quote Originally Posted by Philip Nicoletti View Post
    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)

  4. #4
    Join Date
    Apr 1999
    Posts
    27,446

    Re: error: overloads have similar conversions

    Quote Originally Posted by rjs123 View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center