名前空間
変種
操作

va_start

提供: cppreference.com
< cpp‎ | utility‎ | variadic

Defined in header <cstdarg>
void va_start(va_list ap, parm_n);
va_startマクロは、名前付き引数parm_n続く変数の引数へのアクセスを可能にします.
Original:
The va_start macro enables access to the variable arguments following the named argument parm_n.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
va_startが有効va_listオブジェクトをインスタンスにして呼び出す必要がありますapへの呼び出しの前にva_arg.
Original:
va_start should be invoked with an instance to a valid va_list object ap before any calls to va_arg.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

ap -
va_list型のインスタンス
Original:
an instance of the va_list type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
parm_n -
最初の変数パラメータを前に付けた名前のパラメータ
Original:
the named parameter preceding the first variable parameter
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を拡大しました

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

[編集]

#include <iostream>
#include <cstdarg>
 
int add_nums(int count, ...) 
{
    int result = 0;
    va_list args;
    va_start(args, count);
    for (int i = 0; i < count; ++i) {
        result += va_arg(args, int);
    }
    return result;
}
 
int main() 
{
    std::cout << add_nums(4, 25, 25, 50, 50) << '\n';
}

出力:

150

[編集] も参照してください

次の可変個引数の関数の引数にアクセスします
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.

(関数マクロ) [edit]
可変個引数の関数の引数のトラバーサルは終了します
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.

(関数マクロ) [edit]