using namespace boost;
typedef void (*PtrFunc)(any& );
how to understand above code sample about typedef in c++?
using namespace boost;
typedef void (*PtrFunc)(any& );
how to understand above code sample about typedef in c++?
This code is declaring a typedef called PtrFunc
which is a function type which takes a single parameter of type boost::any&
You can use it like:
void myFunc(any&)
{
....
}
PtrFunc pointerToMyFunc = myFunc;
This is a pointer to a function returning void
and accepting boost:any&
as its sole argument.
It can be used like this:
void someFunction(any& arg)
{
// ...
}
int main() {
PtrFunc fn = someFunction;
// ...
fn(...);
// You can also do this without a typedef
void (*other_fn)(any&) = someFunction;
other_fn(...);
return 0;
}
See this article for a complete guide to reading type declarations in C (and, consequently, C++).
Also, this article provides some ASCII art!