How can i set up a constructor to dynamical manipulate an array?

im having a lot of trouble doing something like so...can you see what im trying to do, where can i find the rules of declaring arrays in class and their member initializers

1
2
3
4
5
6
7
8
struct node
{
char symbol[int x][int y];
node *link;
node ():link(NULL){}
node (symbol [x][y],node *link): symbol[x][y](symbol [x][y]), link (link) {}

};
Last edited on
Two things (at least):

1. in C++, the dimensions for an array should be a constant - so
char symbol[int x][int y]; is incorrect (although GCC might allow it - it is incorrect to the the c++ standard).

2. In C++ - it has never been permitted to assign arrays
to each other (and certainly not initialise a local array from an array passed as a function parameter which as we know is actally passed as a pointer)
- so you cannot initialise the array the way you are attempting
Last edited on
i realised that i couldnt initialize my arrays in this way when my compiler told me it was wrong, i sure would love to know how to, can you see though what i was trying to do? i was trying to get it so could manage the saze of the 2d array dynamicaly; im finding it hard to get an example

1
2
3
4
5
struct node
{
char array [6] [6];
node (): array[6][6] (array [6] [6]){}
};


then why does the above not workify?
Last edited on
So do you just want to set the size of the array dynamically, or do you want to copy an existing array into your new array dynamically?
Last edited on
i would love to see an example of both, that would make everything else i have planned for the code more flexible but copying an existing array into the array is the main aim (both would mean i could copy any 2d array in)
la BUMP
You may use a pointer with operator new[size];
But be careful. Using pointer is extremely dangerous.
I recommend you use vector. This is the best way to go.
Last edited on
But be careful. Using pointer is extremely dangerous.

yes it can blow up your pc and set your house on fire.


probably the problems with your array declaration is, that x and y get set during runtime. you cant declare arrays during runtime, they need a fixed size.
to get rid of this problem have a look at: http://www.fredosaurus.com/notes-cpp/newdelete/50dynamalloc.html

or use http://www.cplusplus.com/reference/vector/vector/
great :D
Topic archived. No new replies allowed.