I need help getting my initializer to work for my project. I get a segmentation fault when I try to print out what I've done. If I could receive any help, I would greatly appreciate it.
#include <iostream>
struct matrix {
protected:
double * * data;
int rows, columns, size;
public:
matrix(int row, int column) {
size = row * column;
columns = column;
rows = row;
data = new double * [size];
}
double * get(int row, int column);
void set(int row, int column, double value);
void resize(int row, int column);
matrix clone();
void print();
void init(double val);
};
.
.
.
void matrix::init(double val) {
for(int i=0; i<rows; i += 1){
for(int i=0; i<columns; i += 1) {
* data[i] = 0.0;
}
}
}
(if you were linked here by my last post, this is what I needed help with before:
Here you allocate memory for size pointers to double. Those pointers, however, point to random places in memory that you do not own, so using those uninitialized pointers results in undefined behavior.