This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to pass 2D variable-sized arrays in C++?


Hi Jason,

Try this out for size:

- - - - - - - - - -
#include <iostream>
using namespace std;

typedef float myarray[3][7];

void foo(myarray& a)
{
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 7; ++j)
            cout << a[i][j] << (j == 6 ? "\n" : " ");
}

int main()
{
    myarray a;
    a[0][0] = 0.0f;
    a[0][1] = 0.1f;
    a[0][2] = 0.2f;
    a[0][3] = 0.3f;
    a[0][4] = 0.4f;
    a[0][5] = 0.5f;
    a[0][6] = 0.6f;
    a[1][0] = 1.0f;
    a[1][1] = 1.1f;
    a[1][2] = 1.2f;
    a[1][3] = 1.3f;
    a[1][4] = 1.4f;
    a[1][5] = 1.5f;
    a[1][6] = 1.6f;
    a[2][0] = 2.0f;
    a[2][1] = 2.1f;
    a[2][2] = 2.2f;
    a[2][3] = 2.3f;
    a[2][4] = 2.4f;
    a[2][5] = 2.5f;
    a[2][6] = 2.6f;
    foo(a);
}
- - - - - - - - - -

--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]