Today I tried to study some piece of code and I am stuck with this line.
std::vector<std::string(SomeClassInterface::*)()> ListOfFnPointers;
what is the meaning of this std::string constructor? I went through this but I have no idea what it means.
It is used in the code as,
if (!ListOfFnPointers.empty())
{
std::vector<std::string> StringList;
for (auto Fn : ListOfFnPointers)
{
StringList.push_back((pSomeClassObj->*Fn)());
}
...
}
pSomeClassObj->*Fn
?It has nothing to do with std::string
constructor.
std::string(SomeClassInterface::*)()
is type of pointer to member function, the member function belongs to class SomeClassInterface
, returns std::string
, takes no parameters.
->*
is pointer-to-member access operator (and also .*
). (pSomeClassObj->*Fn)()
will call the member function on pSomeClassObj
, which is supposed to be a pointer with type SomeClassInterface*
.