In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the function concept of C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the functional concept of C++.
The function of C++
Today we begin to understand the concept of functions in C++.
When it comes to functions, we should be relatively clear that no matter which language has this concept, in fact, it is essentially that the sentences and expressions we introduced before are encapsulated to form a functional unit. It is also the smallest unit of program execution in CAccord Central.We create a new project, and if we want to compile it, we must have a main function main.
But in an interpretive language, it is not necessary, such as js, shell,python, etc. In the future, the Goto language we will introduce, which is also a compiled language, also requires main functions, but in different forms.
Definition of function
First of all, let's talk about the definition method of the function, the function includes the return value, the function name, and the parameter list, the return value can have practical significance, it can also be void, the parameter list can have or not. There is no difference in this C _ blank +. Here is an example of how to define a function:
Static BrewFunction GetBrewFunction (const caffe::string& name) {
If (g_brew_map.count (name)) {
Return g_brew_ map[name]
} else {
LOG (ERROR) width ()
CHECK_GT (mat_num, 0) offset (item_id)
Uni_blob.set_cpu_data (transformed_blob- > mutable_cpu_data () + offset)
Transform (mat_ Vector [item _ id], & uni_blob)
}
}
Look at the transformed_blob above, which is the pointer of type Blob. We can define a variable of this type outside the function, then pass it into the Transform function as an argument, and then we can change the value of the parameter in the function and finally pass it out.
So, from the example above, we can see that the qualifier const appears in the function. What's the use here? Here const is what we talked about before, limited, unchangeable.
That is to say, if we are not going to modify the passed variable in the function, we'd better qualify it with const, of course, this is not necessary, this is just the basic accomplishment of a C++ programmer, a programming habit. Of course, this is also very beneficial.
For example, if you want to develop a library for third-party calls, and you don't want an input parameter to be changed while the code is running, you should use const to enforce qualification.
In addition, if our parameters are relatively large, it is also recommended to use reference parameters to pass to the parameters, because the reference has no entity, is an alias of the original input data, and does not copy the data, so it is more efficient.
Main function to get command line arguments
In many cases, we use the main function to get command-line arguments, so how does this work?
Let's first take a look at the complete definition of the main function:
Int main (int argc, char * argv [])
{
...
}
In the above code, argc represents the number of parameter lists, and argv is the parameter list array. Suppose I have an test_func executable file, and I execute the following command on the command line:
Test_func arg1 arg2 arg3 arg4 arg5
Then we can read in the function that the value of argc is 5 and the values in the parameter list are:
Argv [0] = arg1
Argv [1] = arg2
Argv [2] = arg3
Argv [3] = arg4
Argv [4] = arg5
At this point, I believe that you have a deeper understanding of the "functional concept of C++", you might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.