#149818 - ghuldan - Fri Jan 25, 2008 5:51 pm
Hi,
I want to use an array of (int*), but i have some problems, here is a simplified code ... i just want to theorize, not make you debug my code.
when i try to create and fill one of the (int*) of NoName::array, only the first element of the array (here NoName::array[0][0]) is filled, the rest is nonsense. I think i must be wrong in calling the fill function in NoName::fillArray()
I also tried with :
and
I would really want to know what's wrong here.
Thanks in advance.
I want to use an array of (int*), but i have some problems, here is a simplified code ... i just want to theorize, not make you debug my code.
Code: |
class NoName {
int** array; NoName() { this->array = (int**)malloc(sizeof(int*) * 4); } void fillArray(); } //---------------------- void NoName::fillArray() { fill( &(this->array[0]) ); } //---------------------------------- void fill(int** tab) { (*tab) = new int[100]; for (int i = 0...) (*tab)[i] = 42; } |
when i try to create and fill one of the (int*) of NoName::array, only the first element of the array (here NoName::array[0][0]) is filled, the rest is nonsense. I think i must be wrong in calling the fill function in NoName::fillArray()
I also tried with :
Code: |
//----------------------
void NoName::fillArray() { fill( this->array, 0 ); } //---------------------------------- void fill(int** tab, int num) { tab[num]= new int[100]; for (int i = 0...) tab[num][i] = 42; } |
and
Code: |
//----------------------
void NoName::fillArray() { this->array = fill( this->array, 0 ); } //---------------------------------- int** fill(int** tab, int num) { tab[num]= new int[100]; for (int i = 0...) tab[num][i] = 42; return tab; } |
I would really want to know what's wrong here.
Thanks in advance.