Intersting C++ error message.

Kevin Atkinson kevinatk@home.com
Tue Aug 31 23:20:00 GMT 1999


Nathan Sidwell wrote:
> 
> Kevin Atkinson wrote:
> >
> > skip-t.hh:44: warning: choosing `clone_ptr<FilterItrPart>::operator
> > FilterItrPart *()' over `clone_ptr<FilterItrPart>::operator const
> > FilterItrPart *() const'
> > skip-t.hh:44: warning:   for conversion from `clone_ptr<FilterItrPart>'
> > to `const FilterItrPart *'
> > skip-t.hh:44: warning:   because conversion sequence for the argument is
> > better
> Iif I recall, this overload is ambiguous under ANSI, bug gnu offers the
> above extension. if you use -pedantic-errors, it'll be thrown out.

Perhapes this is not the best place to ask:  Why is it ambiguous, it is
overloading based on the constness of the object, the "this" pointer.

> > Doing so is harmless as the offending methods are.
> >
> >   operator Class * () {return ptr;}
> >   operator const Class * () const {return ptr;}
> >
> > But, I would like to know:
> >
> > 1) Why does it chose the nonconst method over the const one?
> because that is an identity conversion, rather than qualification
> conversion.

When I look at it agian it chooses the non const method becuase "this"
is not const.  So it did to the right thing.  The warning would be
clearer if it said:

choosing ... instead of ... becuase "this" is non const, thus the
conversion sequence for the argument is better.

So how do I suppress the warning?

-- 
Kevin Atkinson
kevinatk@home.com
http://metalab.unc.edu/kevina/



More information about the Gcc mailing list