+ 2
Typedef with c++ pointer
the normal typedef syntax i know is: typedef /*real type name*\ /*alias name*\; but when i trying to create array of function that returning void pointer, stackoverflow say i must use "typedef void (**function_ptr)();" is that a special syntax only for function pointer? why its not using normal typedef syntax? its not homework or something, so you freely to answer it
2 Answers
+ 1
The typedef syntax is a little different for function pointers.
In pointers, the name given alongside the pointer in the typedef declaration becomes the type's name.
Like for a normal array, the typedef statement will be: typedef char _string[50];
Now _string is a type to represent a 50 character array, and you can do :
_string a = "Hello";
Similarly, to declare a typename for a function pointer, you do :
typedef int(*fx)(int,int);
The type, fx, can be used to hold functions that accept two integers and return an integer.
'fx' can be used like this : https://code.sololearn.com/cUNvlu5w8M6B/?ref=app
+ 2
oh well. very good answer. lot of thanks to you.