名前空間
変種
操作

va_arg

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

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
 
Defined in header <cstdarg>
T va_arg(va_list ap, T);
va_argマクロからTva_list..次のパラメーターに対応するタイプapの式に展開
Original:
The va_arg macro expands to an expression of type T that corresponds to the next parameter from the va_list ap.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
呼び出す前va_argに、apva_startに挟まずに呼び出しで、va_copyまたはva_endどちらかの呼び出しによって初期化する必要があります。 va_argマクロの各呼び出しは、次の変数の引数を指すように変更しap.
Original:
Prior to calling va_arg, ap must be initialized by a call to either va_start or va_copy, with no intervening call to va_end. Each invocation of the va_arg macro modifies ap to point to the next variable argument.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
va_argapにそれ以上の引数があるときに呼び出される、またはapの次の引数(登録後)のタイプはTと互換性がない場合、動作はしない限り、未定義の場合:
Original:
If va_arg is called when there are no more arguments in ap, or if the type of the next argument in ap (after promotions) is not compatible with T, the behavior is undefined, unless:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 1型は符号付き整数型であり、他のタイプは、対応する符号なし整数型で、値は両方のタイプで表現可能である場合
    Original:
    one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types; or
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 1型はvoidへのポインタであり、もう一つは文字型へのポインタである.
    Original:
    one type is pointer to void and the other is a pointer to a character type.
    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.
T -
ap内の次のパラメータの型
Original:
the type of the next parameter in ap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

ap内の次の変数パラメータ
Original:
the next variable parameter in ap
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>
#include <cmath>
 
double stddev(int count, ...) 
{
    double sum = 0;
    double sum_sq = 0;
    va_list args;
    va_start(args, count);
    for (int i = 0; i < count; ++i) {
        double num = va_arg(args, double);
        sum += num;
        sum_sq += num*num;
    }
    return std::sqrt(sum_sq/count - (sum/count)*(sum/count));
}
 
int main() 
{
    std::cout << stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n';
}

Output:

0.920258

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

可変個引数の関数の引数にアクセスできるようになります
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.

(関数マクロ) [edit]
(C++11)
makes a copy of the variadic function arguments
(関数マクロ) [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]