In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
The concept of function pointer
When a program is running, all objects related to running need to be loaded into memory, which determines that any object while the program is running can point to it with a pointer. Functions are stored in the code area of memory, and they also have addresses, so they can also use pointers to access functions. This kind of pointer to the function entry address is called function pointer.
First, let's take a look at a Hello World program int main (int argc,char* argv []) {printf ("Hello World!\ n"); return 0;} then, implement void Invoke (char* s) in the form of function calls; int main (int argc,char* argv []) {Invoke ("Hello World!\ n"); return 0;} void Invoke (char* s) {printf (s);} implement void Invoke (char* s) with function pointers. Int main () {void (* fp) (char* s); / declare a function pointer (fp) fp=Invoke; / / assign the entry address of the Invoke function to fp fp ("Hello World!\ n"); / / function pointer fp implements the function call return 0;} void Invoke (char* s) {printf (s);}
When declaring a function pointer, you can declare a function pointer as long as the function returns the same value type, number of parameters, parameter type, and so on. Note that the function pointer must be enclosed in parentheses void (* fp) (char* s).
In practice, for convenience, function pointers are usually declared in the way of macro definition, and the implementation procedure is as follows:
Typedef void (* FP) (char* s); void Invoke (char* s); int main (int argc,char* argv []) {FP fp; / / usually declares a function pointer fp fp=Invoke; fp ("Hello World!\ n") with macro FP; return 0;} void Invoke (char* s) {printf (s);} function pointer array
Let's get a general idea of the function pointer array with the program:
# include # include using namespace std;typedef void (* FP) (char* s); void F1 (char* s) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.