lordleviathon
Programmer
I am having trouble with a matrix class I am writing. It will compile ok, but crashes as soon as I run the program.
On debugging it, I found that the problem occurs in the constructor. It happens when the constructor tries to assign the first value. If anyone could help me I would be grateful.
I have include the relevant code.
#include <iostream.h>
#ifndef MATRIX_OBJ_H
#define MAXTRIX_OBJ_H
typedef unsigned int index_t;
typedef double el_t;
typedef struct matrix_node* pointer_t;
struct matrix_node {
index_t row;
index_t col;
el_t value;
pointer_t right;
pointer_t down;
};
class Matrix {
pointer_t header;
int nonZeroCount;
pointer_t currR;
index_t row, col;
void MakeNode(pointer_t& newNode,index_t i,index_t j, el_t value);
void MakeNode(pointer_t& newNode,index_t i, index_t j);
public:
Matrix(index_t numRows, index_t numColumns);
Matrix(const Matrix& m);
~Matrix();
int numRows() {
return header->row;
}
int numColumns() {
return header->col;
}
int numNonZeros() {
return nonZeroCount;
}
bool isZero() {
return (nonZeroCount == 0);
}
bool rowIsZero(index_t i);
bool columnIsZero(index_t j);
el_t valueAt(index_t i, index_t j);
void setValueAt(index_t i, index_t j, el_t newValue);
Matrix transpose();
Matrix& operator=(const Matrix&);
Matrix operator*(const Matrix&);
Matrix operator*(double);
Matrix operator+(const Matrix&);
Matrix operator-(const Matrix&);
Matrix operator+=(const Matrix&);
Matrix operator-=(const Matrix&);
Matrix operator*=(double);
friend Matrix operator*(double, const Matrix&);
void toFirst();
bool atEndR();
bool atEndC();
void displayMatrix();
void fillMatrix();
};
/*****************************************************/
// Constructors //
/*****************************************************/
Matrix::Matrix(index_t numRows, index_t numColumns) {
header->row = numRows;
header->col = numColumns;
nonZeroCount = 0;
}
On debugging it, I found that the problem occurs in the constructor. It happens when the constructor tries to assign the first value. If anyone could help me I would be grateful.
I have include the relevant code.
#include <iostream.h>
#ifndef MATRIX_OBJ_H
#define MAXTRIX_OBJ_H
typedef unsigned int index_t;
typedef double el_t;
typedef struct matrix_node* pointer_t;
struct matrix_node {
index_t row;
index_t col;
el_t value;
pointer_t right;
pointer_t down;
};
class Matrix {
pointer_t header;
int nonZeroCount;
pointer_t currR;
index_t row, col;
void MakeNode(pointer_t& newNode,index_t i,index_t j, el_t value);
void MakeNode(pointer_t& newNode,index_t i, index_t j);
public:
Matrix(index_t numRows, index_t numColumns);
Matrix(const Matrix& m);
~Matrix();
int numRows() {
return header->row;
}
int numColumns() {
return header->col;
}
int numNonZeros() {
return nonZeroCount;
}
bool isZero() {
return (nonZeroCount == 0);
}
bool rowIsZero(index_t i);
bool columnIsZero(index_t j);
el_t valueAt(index_t i, index_t j);
void setValueAt(index_t i, index_t j, el_t newValue);
Matrix transpose();
Matrix& operator=(const Matrix&);
Matrix operator*(const Matrix&);
Matrix operator*(double);
Matrix operator+(const Matrix&);
Matrix operator-(const Matrix&);
Matrix operator+=(const Matrix&);
Matrix operator-=(const Matrix&);
Matrix operator*=(double);
friend Matrix operator*(double, const Matrix&);
void toFirst();
bool atEndR();
bool atEndC();
void displayMatrix();
void fillMatrix();
};
/*****************************************************/
// Constructors //
/*****************************************************/
Matrix::Matrix(index_t numRows, index_t numColumns) {
header->row = numRows;
header->col = numColumns;
nonZeroCount = 0;
}