Example of Variable Parameter Function writing

Source: Internet
Author: User

Function declaration:

...

// Set the column to be sorted
Void setcolumssortasint (INT nsortcolumcount ,...);

...

 

 

Function body:

/*************************************** **************************************** *****************************
* Function:

* Function: Specify columns in the list control that can be sorted by integers.

* Parameter: nsortcolumcount -- In. Number of columns to be set
... -- In. Column number, separated ','
M_listcolsortasint -- out. Implicit parameter, which stores the specified Column

* Return value: None
**************************************** **************************************** ****************************/
// Set the column to be sorted
Void cmylistctrl: setcolumssortasint (INT nsortcolumcount ,...)
{
// Clear the original data in the linked list
M_listcolsortasint.removeall ();

Va_list argp; // defines the structure for saving function parameters.
Int argno = 0; // number of record parameters
Int intpara = 0; // stores the retrieved integer Parameter

// Argp points to the first input optional parameter. nsortcolumcount is the final parameter.
Va_start (argp, nsortcolumcount );

While (argno <nsortcolumcount)
{
// Retrieve the current parameter (INT type) and save it to the linked list for sorting.
Intpara = va_arg (argp, INT );
M_listcolsortasint.addtail (intpara );
Argno ++;
}
Va_end (argp); // set argp to null
Return;

}

 

M_listcolsortasint is a member of the cmylistctrl class and is defined as follows.

// Record the serial number of the column to be sorted by integer
Clist <int, int> m_listcolsortasint;

 

 

 

The function stores the sequence numbers of columns to be sorted by integers into linked list member variables. Then, you can use the linked list variable to determine whether a column needs to be sorted by integers.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.