A
aurgathor
I'm trying to allocate a 2d array in runtime
that can subsequently be accessed like
arr[x][y], to no avail. Is there any to
do that in C++? If yes, how?
TIA
This is what I got thus far:
#include <iostream>
struct sq_T {
short X;
short Y;
int ID;
};
void maker ( int x, int y ) {
sq_T *display = new sq_T[x*y];
// test code
for (int j = 0; j < y; j++)
for (int i = 0; i < x; i++)
display[(j * x) + i].ID = i + (j*x);
for (int j = 0; j < y; j++) {
for (int i = 0; i < x; i++) {
cout << display[(j * x) + i].ID << " ";
}
cout << endl;
}
}
void main () {
maker(5,7);
}
that can subsequently be accessed like
arr[x][y], to no avail. Is there any to
do that in C++? If yes, how?
TIA
This is what I got thus far:
#include <iostream>
struct sq_T {
short X;
short Y;
int ID;
};
void maker ( int x, int y ) {
sq_T *display = new sq_T[x*y];
// test code
for (int j = 0; j < y; j++)
for (int i = 0; i < x; i++)
display[(j * x) + i].ID = i + (j*x);
for (int j = 0; j < y; j++) {
for (int i = 0; i < x; i++) {
cout << display[(j * x) + i].ID << " ";
}
cout << endl;
}
}
void main () {
maker(5,7);
}