1. Comma operator
A comma expression is a comma-separated array of expressions that are computed from left to right. the result of a comma expression is the value of its rightmost expression . If the rightmost operand
Is the left value, the value of the comma expression is also the left value. This type of expression is typically used for a For loop:
int cnt = Ivec.size ();
for (Vector<int>::size_type IX = 0; IX!= ivec.size (); ++size,--cnt)
{
Ivec[ix] = cnt;
}
The For statement above causes IX to increase by 1 and CNT to subtract 1 in a circular expression. Each loop modifies the value of IX and CNT. When the condition judgment of the Test IX is established, the program will be the next element
Reset to the current value of the CNT.
2. Three mesh (yuan) operator (?:)
Max = (A > B)? A:b
if (a>b) max = A;
else max = b;
X>y 1:1.5 converts 1 to double
3. Function
(1) Built-in functions:
Calling a function requires a certain amount of time and space overhead. C + + provides a way to improve efficiency by locking the calling function code directly into the main function at compile time, this embedding
The functions in the main function are called built-in functions.
Note: Simple functions that are small and frequently called are suitable for declaring as inine functions.
(2) Overload of the function
overloaded functions have the same function name, number of arguments, parameter type, parameter order at least one different
(3) function template
function templates apply to the same function body, the function of the same number of parameters and different types of cases
Template <typename t>//template declaration in which T is a type parameter can also be template <class t>
T Max (t A, T B, t C)//define a universal function, using t as the virtual function name
{
if (b>a) a=b;
if (c>a) a=c;
return A;
}
The type parameter can be more than one, and you can determine the number as needed
such as: template < class T1, TypeName t2>