operator[] ambiguous

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have following program:

class A
{
public:

  A(const char * a);

  operator const char*() const {return data_;}                //the
error message will go away if removing this line

  char& operator[](unsigned int);

protected:
private:
  char* data_;
};


int main() {
    A abc("kkk");
    abc[0] = 'x';
//this is the line causing the error message
    return 0;
}


If I compile with g++, it has following error message:

 ISO C++ says that `char& A::operator[](unsigned int)' and
`operator[]' are ambiguous even though the worst conversion for the
former is better than the worst conversion for the latter

But when I compile it using SunStudio compiler, it works.

I am not quite familar with ISO C++. Could anyone explain where the
ambiguous come from ?

Thanks.

Michael


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux