名前空間
変種
操作

Union declaration

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
union型
関数型
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
組合は、同じメモリ位置にそのすべてのデータメンバを格納する特別なクラス型です.
Original:
A union is a special class type that stores all of its data members in the same memory location.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
組合は、仮想関数を持つことができません継承さや他のクラスを継承し.
Original:
Unions cannot have virtual functions, be inherited or inherit other classes.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11以前)組合はPOD(プレーン古いデータ)タイプのみを含めることができます.
Original:
(C++11以前) Unions can only contain POD(プレーン古いデータ) types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11およびそれ以降)組合は、関数が労働組合では、デフォルトで削除され、ユーザが明示的に定義する必要があることを(コンストラクタ、デストラクタ、コピーコンストラクタまたはコピー代入)ユーザー定義の特別な機能を持つ非PODメンバが含まれている場合.
Original:
(C++11およびそれ以降) If a union contains a non-POD member, which has a user-defined special function (constructor, destructor, copy constructor or copy assignment) that function is deleted by default in the union and needs to be defined explicitly by the user.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 構文

union name { member_declarations } object_list (オプション) ; (1)
union { member_declarations } ; (2)

[編集] 説明

#組合名付けられました
Original:
#Named union
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#匿名組合
Original:
#Anonymous union
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 匿名組合

匿名組合のメンバーは、単一の変数として、外側のスコープからアクセスできます。.
Original:
Members of an anonymous union are accessible from the enclosing scope as single variables.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
匿名組合は、さらに制約を持っている:彼らは唯一のパブリックメンバを持っている必要がありますおよびメンバ関数を持つことができません.
Original:
Anonymous unions have further restrictions: they must have only public members and cannot have member functions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間スコープ匿名組合は、静的なものでなければならない.
Original:
Namespace-scope anonymous unions must be static.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

union foo
{
  int x;
  signed char y;
};
 
int main()
{
  foo.x = 128 + 896;
  std::cout << "as int: "  << (int)foo.x << '\n';
  std::cout << "as char: " << (int)foo.y << '\n';
  return 0;
}

Output:

as int: 1024
as char: 128
(リトルエンディアンプロセッサ用)
Original:
(for little-endian processors)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.