-2

While refactoring a piece of code I came across the line below:

class Bar
{
protected:
    int (Bar::* fooFunction)(float); //this line
}

I have never seen this kind of syntax before. What is this syntax and why is it used it used in C++?

  • 7
    Pointer to member function. As to why it's used, that depends on what the class is supposed to do. –  Aug 17 '17 at 16:04
  • Lookup member function pointer in your favorite search engine. You can start at http://en.cppreference.com/w/cpp/language/pointer. – R Sahu Aug 17 '17 at 16:06

2 Answers2

1

It's a member function pointer.

Specifically, it's a pointer to a member function of a Bar object that takes a float argument and returns a int.

Read more here: http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_member_functions

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
-1

What is this syntax

It declares a pointer to member function.

why is it used it used in C++?

It is used to point to non-static member functions.

eerorika
  • 232,697
  • 12
  • 197
  • 326