Function pointer question.

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

I understand that typeef or using can be used to simplify the use of function pointers.

typedef void func1(int, int);
typedef void (&func2)(int, int);
typedef void (*func3)(int, int);

By the way, I want to know the difference between the above three. In general, the third expression seems to be used a lot, but what's the specific difference?

c++ c++11 function-pointer typedef

2022-09-20 11:30

1 Answers

typedef void (*func3)(int, int); is a function that existed from C language and declared a function pointer as a data type using typeef.

Because it has the properties of a pointer, you can declare the variable alone first and then put the address of the function later, or you can initialize it at the same time as the declaration.

typedef void (&func2) (int, int); is used in the C++ language (the reference operator is from C++) and the function reference is declared in a data format using typeef.

Because it has the nature of a reference, you cannot declare a variable alone (the nickname of the function you want to insert), and you must initialize it at the same time as the variable declaration.

typedef void func1(int, int); is a function that existed from C language and declared a function prototype as a data type using typeef.

This is usually used to hand over a function pointer as a parameter of a particular function and take it as a temporary function (such as a local variable) of that function.


2022-09-20 11:30

If you have any answers or tips


© 2022 pinfo. All rights reserved.