The pointer to member function is called `&C::f` instead of `&f` to make it corresponding to pointers to member variables.
It is possible to create a direct pointer to a member variable, but it is not possible to create a direct pointer to a member function.
I also do not agree with the "I don't care" ones: They should stay forbidden: The decay of the functions to pointers to functions is a C anachronism: We should either use &f or f(), but never f, except for calling.
As a _theoretical_ (!) alternative, references to member variables and references to member functions could be introduced (but are they really needed? And it would not work the same way with free functions due to C compatibility. And references to member variables would not work as the syntax is already used as alternative for normal references, see `d` ):
int f(char);
int a = 4;
static void g() {
int& d = C::a; // current
int& d2 = a; // current
int* f = &b; // current
}
-----Ursprüngliche Nachricht-----
Von: Oleksandr Pikozh via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mi 06.03.2024 13:17
Betreff: Re: [std-proposals] Simplify taking pointer to non-static member function
An: std-proposals@lists.isocpp.org;
CC: Oleksandr Pikozh <o.pikozh@gmail.com>;
I personally like the idea to allow a shorter way (or more ways) of getting non-static member function address:class C {int f(char);static void g() {int C::*fp1(char) = &C::f; // allowedint C::*fp2(char) = &f; // forbidden but IMHO should be allowedint C::*fp3(char) = C::f; // forbidden and I don't careint C::*fp4(char) = f; // forbidden and I don't care}};As for the proposed change of the expression type (so that `&C::f` would contain pointer to `this`, i.e. in fact act as `std::bind_front(&C::f, this)` instead) – I don't support that, IMHO that's too incompatible change.On Tue, Mar 5, 2024, 20:02 ஜெய்கணேஷ் குமரன் via Std-Proposals <std-proposals@lists.isocpp.org> wrote:--Besides personal convenience, there is no point, yes. Anyway, do consider much original suggestion of simply not needing to quality non-static member functions with class name, even if you do not consider this.Remember: we're talking about querying information that you *already
have*. The "this pointer of the current instance" is clearly available
to whomever is writing `&class_name::function`. Besides your personal
convenience, what's the point here?
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
-- Std-Proposals mailing list Std-Proposals@lists.isocpp.org https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals