va_copy
Va[医]复制
Defined in header | | |
---|---|---|
void va_copy( va_list dest, va_list src | | (since C++11) |
大va_copy
宏副本src
到dest
...
va_end
应该被召唤dest
函数返回或随后重新初始化dest
%28va_start
或va_copy
29%。
参数
dest | - | an instance of the va_list type to initialize |
---|---|---|
src | - | the source va_list that will be used to initialize dest |
扩展值
%280%29
例
二次
#include <iostream>
#include <cstdarg>
#include <cmath>
double sample_stddev(int count, ...)
{
double sum = 0;
va_list args1;
va_start(args1, count
va_list args2;
va_copy(args2, args1
for (int i = 0; i < count; ++i) {
double num = va_arg(args1, double
sum += num;
}
va_end(args1
double mean = sum / count;
double sum_sq_diff = 0;
for (int i = 0; i < count; ++i) {
double num = va_arg(args2, double
sum_sq_diff += (num-mean) * (num-mean
}
va_end(args2
return std::sqrt(sum_sq_diff / count
}
int main()
{
std::cout << sample_stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n';
}
二次
产出:
二次
0.920258
二次
另见
va_start | enables access to variadic function arguments (function macro) |
---|---|
va_arg | accesses the next variadic function argument (function macro) |
va_end | ends traversal of the variadic function arguments (function macro) |
c VA文件[医]复制
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。