2007年8月27日星期一

Is the type of "pointer-to-member-function" different from "pointer-to-function"?

[33.1] Is the type of "pointer-to-member-function" different from "pointer-to-function"?

Yep.

Consider the following function:

 int f(char a, float b);

The type of this function is different depending on whether it is an ordinary function or a non-static member function of some class:

  • Its type is "int (*)(char,float)" if an ordinary function
  • Its type is "int (Fred::*)(char,float)" if a non-static member function of class Fred

Note: if it's a static member function of class Fred, its type is the same as if it were an ordinary function: "int (*)(char,float)".

没有评论: