ISO C++ ambiguous error for assignment operator overloading

Discussion in 'C++' started by dany2704, Feb 4, 2013.

  1. dany2704

    dany2704 New Member

    Joined:
    Feb 4, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    String.h has the following operator overloading function which is an user defined
    //declaration
    int operator==(char *ch)
    //definition
    Code:
    int String::operator==(char *ch)
    {
            if (strcmp(_text, ch) == 0)
            {
                    return TRUE;
            }
            else
            {
                    return FALSE;
            }
    }
    The above operator overloading function is called in the file Sample.c The g++ compiler throws the following error.
    String.h:67: note: candidate 1: int String::eek:perator==(char*)
    Sample.c:230: note: candidate 2: operator==(const char*, const char*) <built-in>
    Sample.c:249: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:

    i have pasted the caller code (sample.c)
    230 if (String(StrInputBuffer.part_string(4)) == ":86:")
    {
    //statement
    }
    249 else if (String(StrInputBuffer.part_string(1)) == ":")
    {
    }
    I used the below gnu command to compile the source file
    >g++ -c -g Sample.c -o sample
    compiler version:
    Target: x86_64-redhat-linux
    gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)
    Could you please help me to resolve the issue?

    Thanks for looking into this
     
    Last edited by a moderator: Feb 5, 2013
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    Try to overload or modify this operator definition with const char *ch parameter.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice