0

I am currently reading through some code and came across a few lines I do not understand.

First

void Foo()
{
    (((Type*)parent)->*m_function)();
}

As far as I can tell they are casting the parent to Type and then calling a dereferenced function? I am not sure I have seen the ->*m_function before.

Also I can not see where m_function is declared perhaps here? Which contains more syntax I do not understand. Is it declaring a function that returns void and takes a parameter of a function? But where is the function name?

class Foo()
{
    void (Type::*m_function)();
};
marsh
  • 2,592
  • 5
  • 29
  • 53

1 Answers1

2

It's calling a member function using a pointer to this function: C++ Call Pointer To Member Function

Yes, void (Type::*m_function)(); declares m_function member of type "member function of Type taking 0 args and returning void"

Community
  • 1
  • 1
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112