In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to call C++ function, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
In the language of C++, and in some programming languages, a piece of code that is often needed can be encapsulated and called directly when needed. This is the so-called function in the program. Here is how to call the C++ function in C++.
Not long ago I was asked how to call C++ function in C, the simple answer at that time was to declare the function with extern "C". When asked how to declare the member function in the class, the words stopped for a moment, and then I looked it up on the Internet. There was an article by the father of C++ translated online as an answer, so I brought it to Mark.
Declare the C++ function as ``extern "C"'(in your C++ code), and then call it (in your C or C++ code). For example:
/ / C++ code: extern "C" void f (int); void f (int I) {/ /.}
Of course, this applies only to non-member functions. If you want to call member functions (including virtual functions) in C, you need to provide a simple wrapper. For example:
/ * C code: * / void f (int); void cc (int I) {f (I); / *... * /}
Then, you can call Corel _ rig _ f () like this:
/ / C++ code: class C {/ /... Virtual double f (int);}; extern "C" double call_C_f (C* p, int I) / / wrapper function {return p-> f (I);}
If you want to call an overloaded function in C, you must provide a wrapper with a different name in order to be called by the C code. For example:
/ * C code: * / void favoi (int); void favod (double); void cccc (int iMagical double d) {fimi (I); favod (d); / *. * /
Then, you can use each overload like this.
After reading the above, do you know how to call C++ function? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.