Namensräume
Varianten
Aktionen

va_copy

Aus cppreference.com
< cpp‎ | utility‎ | variadic

Defined in header <cstdarg>
void va_copy(va_list dest, va_list src);
(seit C++11)
Die va_copy Makro kopiert src um dest .
Original:
The va_copy macro copies src to dest.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
va_end sollte auf dest bevor die Funktion zurückkehrt oder eine spätere Re-Initialisierung des dest aufgerufen werden (über Anrufe va_start oder va_copy) .
Original:
va_end should be called on dest before the function returns or any subsequent re-initialization of dest (via calls to va_start or va_copy).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Parameter

dest -
eine Instanz der va_list geben zu initialisieren
Original:
an instance of the va_list type to initialize
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
src -
die Quelle va_list, die verwendet werden, um dest initialisiert werden
Original:
the source va_list that will be used to initialize dest
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Expanded Wert

(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

#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;
    }
    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);
    }
    return std::sqrt(sum_sq_diff / count);
}
 
int main() 
{
    std::cout << sample_stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n';
}

Output:

0.920258

[Bearbeiten] Siehe auch

ermöglicht den Zugriff auf variadische Funktionsargumente
Original:
enables access to variadic function arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funktionieren Makro) [edit]
greift auf die nächsten variadische Funktionsargument
Original:
accesses the next variadic function argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funktionieren Makro) [edit]
endet Durchlaufen der variadische Funktionsargumente
Original:
ends traversal of the variadic function arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funktionieren Makro) [edit]