C ++ overload resolution for const member functions

Suppose you have a class T with two member functions

  • char foo() const {...}
  • char foo() {...}.

I understand that when calling constant T we solve (1); and for unstable T we solve (2).

  • It is right?
  • which rule is invoked in this permission? (link to the standard excellent but useful summary was appreciated)

Notes:

  • I tried to use Google to do this, but the old hits I got were cases for other const overload permissions. However, the reference to the old SO, actually explaining the above, is obviously great.

  • This came about when reading Stroustrup “C ++ Programming Language”, second edition (“Special Edition”), an example of String / Cref in section 11.12, page 296. Since Stroustrup is so accurate, the answer may be in the previous sections, but I don’t see where. A link to sections in the Straustrup is also very welcome (2nd edition is best, as I have). Section 10.2.6 presents const members as those that “do not change the value of the object”, which hints at the answer, but does not call me a clear-cut directive.

+4
source share
1 answer

In N3242 (the standard project that I have at hand), 13.3.1 in paragraph 4 states

- "lvalue reference to cv X" [non-static member], ref-qualifier ref

, , , " lvalue cv X", X , cv cv- - ( .. const const). .

, -, "" , .

const const ( "" ), . non-const- , const .

const non-const , "" - 13.3.3.2, .

S1 , S2, ...

S1 S2 , , cv- , , , S2, cv-, , S1 .

+4

Source: https://habr.com/ru/post/1524616/


All Articles