Talk:cpp/language/member functions
Contents |
[edit] no ref-qualifiers
The page says: "During overload resolution, non-static cv-qualified member function of class X is treated as a function that takes an implicit parameter of type lvalue reference to cv-qualified X if it has no ref-qualifiers or if it has the lvalue ref-qualifier". So it seems from this text that "no ref-qualifiers" and "lvalue ref-qualifier" should work exactly same. But for g++ 20161124 this is not true. Look at this code:
struct foo { void operator() () & { } }; int main (void) { foo x; foo ()(); }
g++ doesn't compile this code. But if I change "operator() () &" to "operator() ()", the code compiles. So (as it seems from g++ 20161124 behavior) there is difference between "no ref-qualifiers" and "lvalue ref-qualifier". So, please, change the page. I used g++ from Debian package gcc-snapshot 20161124-2. Safinaskar (talk) 10:47, 5 December 2016 (PST)
- The sentence you're referring to is correct (it's 13.3.1[over.match.funcs]p4), but indeed incomplete, it's missing 13.3.1[over.match.funcs]p5.1 which imposes an additional rule allowing rvalues to bind to non-const lvalue reference implicit object parameters, but only when it belongs to a function with no ref qualifier. This appears here on cpp/language/overload_resolution#Details, but it's worth adding it to this page as well, thanks. --Cubbi (talk) 11:36, 5 December 2016 (PST)
- Thanks. Safinaskar (talk) 05:47, 6 December 2016 (PST)
[edit] Purpose of & and && qualifier
It would be nice if it is explained what these qualifier are good for, either in text or as a better example code. --Roker (talk) 02:45, 20 November 2018 (PST)
[edit] Redirection of "member function" to "non-static member function"
Static member functions exist as well. While cpp/language/classes mentions them explicitly and link to appropriate pages of the wiki, other pages like cpp/language/functions and cpp/language/function just have links for "member function" that redirect here. I think this redirection is a mistake.
Here are my proposed solutions (in order of preference):
- Add a small paragraph on top of the page about the existence of a section on static member functions on the wiki and link to it. (though that might involve repeating text from that article)
- Add a subheading in cpp/language/classes before "A class can have the following kinds of members", redirect member_function to that subheading. Move this page from member_functions to non_static_member_functions.
- Rewrite the entire page.
Chandradeep Dey (talk) 01:21, 9 June 2020 (PDT)
- good point, added a link to static m.f. from the top of this page, and others made edits elsewhere. --Cubbi (talk) 11:21, 9 June 2020 (PDT)
- Thanks Chandradeep Dey (talk) 13:00, 10 June 2020 (PDT)
[edit] Top of page example:
What does
void mf2() volatile, mf3() &&;
- This is equivalent to two separate member-function declarations with the same return value
void:
class S { // ... void mf2() volatile; void mf3() &&; // ... }; // consider: struct R { int x() const, y() volatile, z() const volatile; }; int R::x() const { return 0; } int R::y() volatile { return 1; } int R::z() const volatile { return 2; }
- --Space Mission (talk) 17:47, 8 October 2020 (PDT)
- I don't know why that didn't occur to me, thanks! I sometimes forget about things like
unsigned typedef int uint;working and such. I feel silly now! Thanks for the speedy reply too 217.45.105.153 19:18, 8 October 2020 (PDT)
- Well, this case with functions is not that obvious anyway. :-)
- I don't know why that didn't occur to me, thanks! I sometimes forget about things like