I came across some C++ code which looks roughly like this:
void (classA::*methodA)() const noexcept
{
&classA::methodB
};
Note: obviously I’m abstracting out the class name and method names in this example.
What is the purpose of methodA
?
Analysis of the code
- It appears to be referencing
methodB
, but without parentheses, so it doesn’t appear to be calling the method - It uses ampersand
&
which reads to me astake the address of
- Lastly
methodA
doesn’t return anything
Overall it appears to be just referencing the address of
methodB.
Any suggestions as to what this is accomplishing?
Source: Windows Questions C++