Hello

I'm working on a project, and I have the following classes:

  • Loader - This loads the contents of the text file
  • Matrix - This processes the data that has been loaded

Now I'm using association, Loader -> Matrix

In my matrix class I have a method that calls the object of the loader:

bool Matrix::Load()
{    
    
    if(!loader.Read(file_location))
    {
        return false;
    }
    
    int* data = loader.getData();
    
    for(int i=0; (i < columns); i++)
    {
        for(int j=0; (j < rows); j++)
        {
            matrix[i*rows+j] = data[i*rows+j];
        }
    }    
    
    return true;
}

In my Matrix class I'm defining a new object of the Loader class:

Loader loader;

Everything is fine, it all works, right up until I initialise a new object in main of class Matrix, then it returns either a Bus error or a Segmentation fault: 11..

I haven't done Association in a long time, but, I think it's something to do with how I'm initialising the loader Object.

Anyone have any suggestions?

right up until I initialise a new object in main of class Matrix

Post that code and Loader code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.