Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the initializer_list parameter of Clipper 11

Shulou Source: shulou.com Published: 2022-06-01 19:12:09 10月03日 Update

This article mainly explains how to use the initializer_list parameter of Clipper 11. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the initializer_list parameter of Clipper 11.

Variable parameters in C language

The most common example is the magic printf function, which can adjust the number of parameters according to the needs of users. In fact, we can also design functions with variable parameters. For example, the following function can determine the number of input parameters based on the first parameter.

Int test (int num,...)

{

Int I, result = 0

Va_list parlist

Va_start (parlist, num); / / prepare the parameter list

For (I = 0; I < num; iTunes +)

{

/ / get each parameter, and the type is determined by the second parameter of av_arg

Printf ("% d\ n", va_arg (parlist, int))

}

Va_end (parlist); / / closes the parameter list

Return result

}

The number of subsequent parameters of test is determined by the first parameter, number. With such a test function, you can determine the number of parameters as needed. The following code all works properly:

Test (2,10,20); test (4,1,2,3,4)

Variable parameters in Clippers 11

Clocking 11 provides the initializer_list class in the standard library to handle situations where the number of parameters is variable but the type is the same. The most common way to use initializer_list is to initialize it with a list of values surrounded by curly braces:

Initializer_list vlist {9, 8, 7, 6}

Except that the value in vlist cannot be modified, it can be used like a normal list.

Continue to look at the following functions:

Template

Void output (initializer_list lst)

{

For (auto & a: lst) {

Cout

Tags: Parameters functions number variable parameter content that is situation type face learning same magic code examples actions frequent common common mood Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Huawei Docker Xiaomi