Re: Overloaded method resolution order

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

 



Stuart Brooks wrote:

According to Stroustrup (7.4), certain criteria are tried in order, so as to
determine which matches the closest. I would have thought that, at least in
the case of s2 (above), the "const char* getString() const" method would
have been selected. I had also hoped that since the second one was
protected, it would use the first one instead in any case. Am I missing
something here?

yes. G++'s behaviour is correct. The non-const version is selected because the object is non-constant. therefore an exact match is a better conversion than the qualification conversion (as the latter contains the former). Access is not considered until after overload resolution. That separation allows you to relax the access on a member and not break an already working program.

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@xxxxxxxxxxxxxxxx    ::     http://www.planetfall.pwp.blueyonder.co.uk


[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