Hello!
Just started c++, got some experience from java, arrays were alot easier there.
I want to make a Class and initialize a 2 dimensional int array there, but the length of each dimension should be declared in the constructor.
unfortunately i dont know how to initialize an 2-dim array without specifying its length... like int x[][]; doesnt work. :(
maybe someone can show me, coudlnt find anything helpful on web. :)
Kaisky
1 2 3 4 5 6 7 8 9 10 11
class Matrix {
public:
Matrix(int, int);
int dimX, dimY;
int x[dimX][dimY]; // of course this doesnt work
};
Matrix::Matrix(int dimx, int dimy) {
dimX = dimx;
dimY = dimy;
}
edit:
also i would like to set dimX and dimY to constint, but then i cant set it in the constructer anymore :(
Allocate the data (what you call 'x') as a single dimensional, dynamic array.
Create a private function to turn an (x,y) pair into an index into that array.
Use it to access data.