mercredi 4 décembre 2019

Function cannot access objects variables c++

I have a node object which contains 2 arrays. One of the arrays is supposed to fill in data from a file. I am not having trouble loading in the file, but every time the function is called to add a value into the array it does not add it.

Here is the array, defined in the public section of the node class

float valueList[832];

And here is the way I am using it

void node::add(float data)
{
    this->valueList[this->size] = data;
    this->size = this->size + 1;
}

in main (value is being added to a node in a 63 x 63 array of nodes):

                        if(!isValid(arr[xCount][yCount]))
                        {
                            node a(0, false, xCount, yCount);
                            addToArray(a);
                            myFile.read((char *) &dataIn, 4);
                            a.add(dataIn);
                            yCount++;
                        }
                        else
                            {
                                myFile.read((char *) &dataIn, 4);
                                node b = arr[xCount][yCount];
                                b.add(dataIn);
                                yCount++;
                            }

I am having trouble accessing the data using arr[x][y] even though there is a node at that spot.

Aucun commentaire:

Enregistrer un commentaire