Surprisingly, the following code compiles well both in gcc and clang no matter what symbol before function name is used: *
, &
or nothing. Does standard allow any of them? What is preferred way to store function pointers?
#include <stdio.h>
typedef int foo(int a);
template <typename X>
int g(int y) {
return y * sizeof(X);
}
int main() {
foo* xxx;
// 1. what is correct according to standard?
// 2. why they all work?
xxx = *g<float>;
xxx = &g<float>;
xxx = g<float>;
printf("ok %d\n", xxx(5));
}
&ClassName::functionname
will work. – Clevelandclevengerxxx = &&&&g<float>
also works. And when you call through that pointer you can write(*xxx)(5)
or(**xxx)(5)
or even(******xxx)(5)
. – Saurel