4

関数から別の関数に 2D 配列を渡そうとしています。ただし、配列のサイズは一定ではありません。サイズはユーザーが決定します。

私はこれを研究しようとしましたが、あまり運がありませんでした。ほとんどのコードと説明は、配列の一定サイズに関するものです。

私の関数Aでは、変数を宣言し、それを少し操作してから、 Function に渡す必要がありますB

void A()
{
      int n;
      cout << "What is the size?: ";
      cin >> n;

      int Arr[n-1][n];

      //Arr gets manipulated here

      B(n, Arr);
}

void B(int n, int Arr[][])
{
    //printing out Arr and other things

}
4

3 に答える 3

11

std::vector動的サイズの配列が必要な場合に使用します。

std::vector<std::vector<int>> Arr(n, std::vector<int>(n - 1));
B(Arr);

void B(std::vector<std::vector<int>> const& Arr) { … }
于 2013-10-28T07:30:06.440 に答える
3

配列のサイズは一定である必要があります。または、 を使用std::vector<std::vector<int>>して動的 2D 配列を表すこともできます。

于 2013-10-28T07:30:05.127 に答える