
-----------------------------------
one
Tue Jan 20, 2009 9:25 pm

Creating Multidimensional Array with a Nonconstant value
-----------------------------------
Variable inputted- a
The array is of integer type and 3 of the dimensions are known 
Eg: int array
How would you do that?

For 2d array its like this:
int **a;
int rows=3,cols=4;//3X4 matrix
a=new int* 

So what would you do for 4d?

Thanks



Mod Edit: Remember to use syntax tags! Thanks :) [syntax="cpp"]Code Here[/syntax]

-----------------------------------
OneOffDriveByPoster
Tue Jan 20, 2009 11:09 pm

Re: Creating Multidimensional Array with a Nonconstant value
-----------------------------------
If you understand the following declaration, then see what you can do with it:
int *array

-----------------------------------
md
Wed Jan 21, 2009 8:26 pm

RE:Creating Multidimensional Array with a Nonconstant value
-----------------------------------
you could use a typedef - always fun...

-----------------------------------
wtd
Sat Jan 24, 2009 3:03 pm

RE:Creating Multidimensional Array with a Nonconstant value
-----------------------------------
You should be creating your own wrapper class so all of this munging about in three dimensional arrays is hidden from the main logic of your program.

A hint:

template 
class Matrix3D
{
    public:
        Matrix3D(size_t x, size_t y, size_t z, T init_val);

        // Add member functions as needed to manipulate and access "data".

    private:
        size_t x_size, y_size, z_size;

        T* data;  
};

template 
Matrix3D::Matrix3D(size_t x, size_t y, size_t z, T init_val)
: x_size(x), y_size(y), z_size(z)
{
    // Initialize "data" here
}
