Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ampersand in `std::is_member_function_pointer`?

The example of use of std::is_member_function_pointer on cppreference uses an ampersand and I have some difficulties to understand the syntax.

#include <type_traits>

class A {
    void member_function() { }
};

int main()
{
    // fails at compile time if A does not contain member_function as a function.
    static_assert(std::is_member_function_pointer<decltype(&A::member_function)>::value,
                  "Class does not contain member."); 
}

What is the meaning of &A::member_function and do A::member_function has a meaning (and if yes, what is the difference) ?

Furthermore, does std::is_member_function_pointer work with function templates ?

like image 430
Vincent Avatar asked May 25 '26 17:05

Vincent


1 Answers

This expression

&A::member_function

literally means a member function pointer. The & is used to get the pointer.to a member function.

like image 105
Vlad from Moscow Avatar answered May 28 '26 06:05

Vlad from Moscow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!