9

There is a segment of code incomprehensible when my friend was reading this hpp file. Specifically,

  • what does certain formation such as A(B, C), int(int, int), or in this case T(Type::*) means? I've already seen usages such as std::function<int(int, int)>, but still have no idea what int(int, int), alone, means.
  • what does Type::* mean? How can a asterisk mark follows :: directly?
CXuesong
  • 552
  • 5
  • 12
  • Is `Type` a namespace? – Dominique Jun 12 '18 at 13:13
  • *"but still have no idea what `int(int, int)`, alone, means"* -- `int(int, int)` is the type of `int f(int, int)`. You should figure out what this declaration means (`f` is a function that takes two `int` arguments and returns an `int`). – axiac Jun 12 '18 at 13:14
  • related: https://stackoverflow.com/questions/670734/c-pointer-to-class-data-member – NathanOliver Jun 12 '18 at 13:16
  • @Dominique It is more likely to be a type name, I suppose. – CXuesong Jun 12 '18 at 13:19
  • @axiac So you mean `int(int, int)` is actually a type of function? I've never thought of that, because I've seen something like `int (*func)(int, int)`, i.e. function pointer types pretty much, but not the function types themselves. – CXuesong Jun 12 '18 at 13:24

1 Answers1

7

::* is used to declare a pointer to a member of class. So in this case, it's pointing to a member of the template type callled Type.

std::function<int(int, int)> is an std::function for holding a method that takes paramters of (int, int), and returns an integer result. (This is an example of the famously complicated C/C++ type declaration syntax).

Baldrick
  • 11,712
  • 2
  • 31
  • 35