我想在c中编写一个具有可变数量参数的函数..有人可以指导我..
2 回答
            2        
        
		
此类函数调用省略号: http: //www.learncpp.com/cpp-tutorial/714-ellipses-and-why-to-avoid-them/
因为省略号很少使用,很危险,我们强烈建议避免使用,本节可以视为可选阅读。
如果您仍然需要这样的功能,请看一下这个示例(重点是 va_list):
double FindAverage(int nCount, ...)
{
    long lSum = 0;
    // We access the ellipses through a va_list, so let's declare one
    va_list list;
    // We initialize the va_list using va_start.  The first parameter is
    // the list to initialize.  The second parameter is the last non-ellipse
    // parameter.
    va_start(list, nCount);
    // Loop nCount times
    for (int nArg=0; nArg < nCount; nArg++)
         // We use va_arg to get parameters out of our ellipses
         // The first parameter is the va_list we're using
         // The second parameter is the type of the parameter
         lSum += va_arg(list, int);
    // Cleanup the va_list when we're done.
    va_end(list);
    return static_cast<double>(lSum) / nCount;
}
    于 2013-04-10T10:57:20.363   回答
    
    
            0        
        
		
return_type function name(int arg1,int arg2,....argn)
{
}
也可以参考,
于 2013-04-10T11:00:46.733   回答