I experimented with function types in C ++. Note that I do not mean the types of pointers to a function like:
typedef void (*voidFuncPtr)();
but all the more exotic:
typedef void (voidFunc)();
I did not expect the following code to compile, but surprisingly this happened:
template<voidFunc func> class funcClass { public: void call() { func(); }; }; void func() { } void Test() { funcClass<func> foobar; foobar.call(); }
however, if I try to add the following to funcClass:
voidFuncPtr get() { return &func; }
I get an error message Address expression must be an lvalue or a function designator
My first question here is: what kind of black magic is used by the compiler to pretend that the type func is what it really can pass around the instance? Is it just treating it like a link? The second question: if it can even be called, why cannot it be addressed to him? Also, what are these non-pointer types called? I just opened them because of boost :: function and could never find documentation about them.
Brent source share