Could someone let me know if this is the correct definition of this datatype and if the way I've initialised it is correct?
typedef int const * (* const DataOne)(const int *);
=> The above datatype shows a constant pointer to a function that takes a pointer to a constant int
as a parameter and returns a pointer to a constant int
.
=> initialised and declaration: DataOne = &myFunction(7);
typedef int const * (* const DataOne)(const int *);
=> the above datatype shows a constant pointer to a function that takes a pointer to a constant int as a parameter and returns a pointer to a constant int.
Correct.
=> initialised and declaration: DataOne = &myFunction(7);
Not correct. Function pointer assignment cannot be made on a function call (ie you cannot have any actual arguments for the parameters). Also, DataOne is a type, not a variable. So, it should look something like this:
int const * myFunction(const int*);
DataOne myPointer = myFunction; // &myFunction would also work
To declare an equivalent function pointer without a type:
int const * myFunction(const int*);
int const * (* const functionPointer)(const int *) = myFunction;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.