Template Function Pointer

I am confused by what is happening here, and I was hoping that one of you, the guru, would help me understand. I overtook this class with methods that seem relevant, hope I didn't miss anything.

template < int* ( foo::*member_function )( void ) >
class bar
{
public:
    int myFunc( foo* myFoo )
    {
        int* result = ( myFoo->*member_function )();
        return *result;
    }
};

I donโ€™t understand how this has an idea of โ€‹โ€‹what member_function is, there is no variable, but it is called, and does someone help me here?

+3
source share
2 answers

member_function is the name of the template parameter specified in:

template < int* ( foo::*member_function )( void ) >

That is, the template parameter member_functionis a member function foothat takes no arguments and returns int*.

bar - bar<&foo::a_member_function> b;, member_function - foo::a_member_function. , myFunc, foo, - foo.

+4

, ; :

[C++11: 14.1/1]: , , ( cv-) :

  • ,
  • ,
  • lvalue lvalue ,
  • ,
  • std::nullptr_t.

.

+6

All Articles