Typedef with c++ pointer | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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

24th May 2018, 4:57 AM
Kevin AS
Kevin AS - avatar
2 Antworten
+ 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
24th May 2018, 6:55 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
oh well. very good answer. lot of thanks to you.
24th May 2018, 12:50 PM
Kevin AS
Kevin AS - avatar