);~ Stack ();Void push (T );T POP ();//...};In the preceding definition, the template tells the compiler that this is a template. The Except for specifying the template parameters when declaring a class template, the other classes are the same as common classes. For example:Stack Stack Stack Int_stack.push (10 );Ch_stack.push ('Z ');Str_stack.push ("C ++ ");(2) function TemplateSuppose we want to define a max function to return the setter of two values of the same type (this type is allowed to
templates, in addition to specifying template parameters at the time of declaration, is the same as for ordinary classes, for example:StackStackStackInt_stack.push (10);Ch_stack.push (' z ');Str_stack.push ("C + +");(2) function templateSuppose you now want to define a max function to return the largest of two values of the same type (this type is allowed to be compared).TemplateT Mymax (const t t1,const t T2){return T1 The meaning of template The us
:length= Length+1returnlength#function CallStr_len =Mylen ()Print('Str_len:%s'%str_len)return a valueReturn multiple valuesCan return any number of values of any data typedefret_demo1 ():" "return multiple values" " return1,2,3,4defRet_demo2 ():" "returns multiple values of any type" " return1,['a','b'],3,4Ret1=Ret_demo1 ()Print(RET1) Ret2=Ret_demo2 ()Print(Ret2) returns multiple valuesreturn multiple valuesIv. parameters of the functionReal participation Formal parametersThe actual value
commas between multiple parameters. (example Below)def Mymax (x, y): the_max = x if x > y else y return the_maxma = Mymax (10,20) print (ma) Position parametersStand at the angle of the argument1, according to the location of the valuedef Mymax (x, y): #此时x =10,y=20 the_max = x if x > y else y return the_maxma =
is called the Pass parameter, referred to as the argument, we call the function when the "Hello World" and the definition of the function S1 is the parameter .Real participation Formal parametersThe parameters are also different:The "Hello World" passed when we called the function is called the actual argument, because this is the actual content to be given to the function, referred to as the argument . The S1 that defines a function is simply the name of a variable, called the formal parameter
, referred to as the argument.When defining a function, the S1 is simply the name of a variable, called the formal parameter. Because it is only a form when defining a function, it means that there is a parameter, called the formal parameter.Parameter passing:Passing Multiple parametersParameters can be passed multiple, separated by commas between multiple parameters. (Example below)def Mymax (x, y ): if Else y return =
"Hello World" passed when we called the function is called the actual argument, because this is the actual content to be given to the function, referred to as the argument . The name of the variable that defines the function is called the formal parameter , because it is only a form when defining a function, which means that there is a parameter, referred to as a formal argument.Passing Multiple parametersParameters can be passed multiple, and multiple parameters are separated by commas.def
>v2; V2.push_back (1); V2.push_back (2); BOOLR5 = compareint> >:: IsEqual (v1, v2); //Custom template classspecializedtypefloat> S1 = {10.1f,10.2f}; Specializedtypefloat> s2 = {10.3f,10.0f}; BOOLR6 = comparefloat> >::isequal (S1, S2);the specificity of C + + function templatesfunction template is special, function template only fully special, no semi-specialLook at the following exampleMain () { int highest = Mymax (5,ten); char c =
passed:Multiple parameters can be passed. Multiple parameters are separated by commas.
Location parameters
From the perspective of real parameters
1. Pass values by location
Def mymax (x, y): # at this time x = 10, y = 20 the_max = x if x> y else y return the_maxma = mymax () print (ma)View Code
2. Pass values by keywords
Def mymax (x, y): # at this time x = 20,
( -32.90) #求绝对值.Math.factorial (n) #求n的 factorialIn the edit window, enter "math." and move the mouse cursor to "." You can open the math list with a little pause.2.5 lambda functionPython allows you to define a small single-line function. The form of a lambda function is defined as follows:Lambda Where parameters are separated by commas. The lambda function returns the value of an expression by default. You can also assign it to a variable. A lambda function can accept any parameter, including
Templates in C ++ are classified into class templates and function templates,. Special Template
(1) Special Class Template
Sometimes for the sake of need, for specific types, the template needs to be made special, that is, special processing. for example, a stack template is applicable to the bool type. In fact, the bool type requires only one binary bit to store it. Using one word or one byte is a waste of storage space.
Template
Class Stack {};
Template
Class Stack
In the preceding definit
multiple, and multiple parameters are separated by commas.def mymax (x, y): The_max = x if x > y else y return the_maxma = Mymax (10,20) print (MA)It is precisely because you need to pass multiple parameters, you can pass multiple parameters, you will have the following series of parameters related to the story ...Position parametersStanding at the argument angle1. Transfer Values by locationdef
boxAlthough the algorithm handles different types of data, the algorithm itself is the same, and the function template can be used to simplify the work and reuse the code.Syntax format for function templates:Template return value type function name (formal parameter list){function body}For example:Custom comparison function templatesT is the parameter of the function templateTemplateT Mymax (const T a,const t B){Return a>b? A:B;}Identifiers defined w
) According to the location of the transfer parameterdef Mymax (x, y ): # at this time x=10,y=20 if Else y return = Mymax (10,20)print(MA)(2) Follow the key wordsdef Mymax (x, y ): # at this point x = 20,y = Ten Print (x, y) if Else y return = Mymax (y = 10,x =)print(MA)(3) position, keyword mi
When defining a function, we determine the parameter name and position of the function, the interface definition of the function is complete, and when using the parameter, we can use the default parameter, the variable parameter and the keyword parameter in addition to the required parameter, and the function can handle the various incoming data.First, Position parameters1. Pass the parameter by location1 def Mymax (x, y): 2 if Else y 3 return
several values, receives them with several variablesA,b,c,d =Ret_demo2 ()Print(a,b,c,d)receive with multiple variablesParameters of the functionTells the function to calculate what the number is to pass the argument.The purpose of the argument is to use it in the function and bring the same formula with different numbers.Arguments have arguments and formal parametersarguments: The calling function is passed in.Kind and definition order:1. Pass the parameter by position, * () or *[] form can pas
functions2, there is a parameterPass what is what3, with multiple parametersBy location parameterAt the angle of the argument:Pass the parameter by locationdef Mymax (x, y ): # at this time x=10,y=20 if Else y return = Mymax (10,20)print(MA)Follow the key word parametersdef Mymax (x, y ): # at this point x = 20,y = Ten Print (x, y) if Else y
Dynamic library call problems Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061207153631108.html
Used for calling in Delphi
Function mymax (X, Y: integer): integer; stdcall; External 'project1. dll '; shenming
Who knows how to call in VC?
typedef int winapi (t_mymax) (int I, Int J); // declare the function type hinstance glib = NULL; // DLL handle t_mymax mymax; // declare
:numvariables) {VectoriMiniMaxiif (miniif (Maxi>mymax) {Mymax}# Plot the variablesFor (i in 1:numvariables) {VectoriNameiColouriif (i = = 1) {Plot (vectori,col=colouri,type= "L", Ylim=c (Mymin,mymax))}else {points (vectori,col=colouri,type= "L")}LastxvalLastyvalText ((lastxval-10), (lastyval), namei,col= "Black", cex=0.6)}}# For example, in order to draw a contou
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.