GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::array::初期化 - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. array
  3. array
  4. 初期化

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

<array>

std::array::初期化(C++11)

namespace std {
  template <class T, size_t N >
  struct array {
    T elems[N]; // public。変数名は実装依存。

    // コンストラクタの定義なし
  };
}

概要

arrayクラスは、固定長配列のコンテナである。静的に決定される要素数を持ち、組み込み配列のラッパーとして実装される。

arrayクラスはpublicな配列メンバ変数を持ち、非トリビアルなコンストラクタを提供しない。そのため、arrayは集成体の要件を満たす。これにより、arrayクラスは組み込み配列と同様の初期化構文を使用して初期化を行うことができる。

例

#include <iostream>
#include <array>

int main()
{
  // int型を3要素持つ配列型オブジェクトの初期値を設定
  std::array<int, 3> ar = {1, 2, 3};

  for (std::size_t i = 0; i < ar.size(); ++i) {
    std::cout << ar[i] << std::endl;
  }
}

出力

1
2
3

バージョン

言語

  • C++11

処理系

  • Clang: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: 2008 (std::tr1) ✅, 2010 ✅, 2012 ✅
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.