When you wrote
META POS:: *member
this means that member
is a pointer to a member of class POS
that has type META
.
Now coming to your second question,
Can anyone let me how to call this function?
One possible example is given below:
#include <iostream>
#include <string>
struct Name
{
std::string name;
Name() = default;
Name(std::string pname): name(pname)
{
std::cout<<"Constructor called"<<std::endl;
}
};
template<class POS, class META>
size_t test11( META POS:: *member)
{
//create object of type Name
Name n("Anoop");
//create a pointer to object n
Name *ptrN = &n;
//Now let's use the variable member
std::cout<<ptrN->*member<<std::endl;
return 5;//don't forget to return something since the function has non-void return type
}
int main()
{
//create a pointer to non-static member
std::string Name::*ptrData = &Name::name;
//pass the pointer ptrData to the template function test11<>
test11(ptrData);
}
The output of the program is:
Constructor called
Anoop
which can be verified here.
Explanation
When i wrote
test11(ptrData);
in the above code sample, then using template argument deduction, POS
is deduced to be the type Name
and META
is deduced to be the type std::string
.