This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How do I avoid this warning?


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]