0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C++】指示付き初期化

0
Posted at
2021/02/09

C++20では、波カッコによる集成体初期化においてメンバ名を指定して初期化が行える。

メンバの宣言順でしか指定できない、通常の初期化子と混在できないなど制約が多い。
ただ、この機能でしか出来ないこととして、共用体の任意のメンバの初期化が挙げられる。

union {
    uint32_t n_;
    float f_;
} work = { .f_ = 1.f };  // C++ 14 では先頭のメンバしか初期化出来ない
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?