How do I avoid this warning?

Dave Williss dwilliss@microimages.com
Thu Jul 18 08:01:00 GMT 2002


I get a lot of warnings of the type:

    warning: choosing `FOO::operator BAR*()` over `FOO::operator const
BAR*()
        for conversion from FRED to const BAR*
        because conversion sequence for the argument is better

How do I code so that the conversion won't be better?

I was going to ask if there was an option to disable this warning, but I can
see a case where this really would be incorrect behavior.  If the const
operator returns a pointer to internal data directly and the non-const has
to make a copy that the caller is expected to free, calling the non-const
method when the const was intended would give unexpected results (and leak
memory). This is just a hypothetical situation, but supports the need for
the warning.

So how do I force it to behave and call the correct method?

 -- Dave Williss
------
Meddle not in the affairs of dragons,
   for you are crunchy and taste good with catsup




More information about the Gcc-help mailing list