472,975 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

Deletion of a matrix

In one of my header-files I have a class named "matrix" with the function to
construct a matrix. It works properly but at the time of destruction of the
class the program stops. What have I done wrong? Thanks in advance Dieter

class matrix

{

public:

matrix* next;

int xDim;

int yDim;

int **field;

~ matrix()

{

for (int line=0; line<xDim; line++)

delete [] field[line];

delete [] field;

// delete next;

};

matrix::matrix(int x, int y)

{

int i, j;

xDim=x;

yDim=y;

field = new int* [xDim];

for(i=0; i<xDim; i++)

field[i] = new int [yDim];

for(i=0; i<xDim; i++)

for(j=0; j<yDim; j++)

field[i][j]=INT_MAX;

}

void Setnext (matrix* ne) {next=ne;}

matrix* Getnext () {return next;}

void Setmatrix (int Lines, int Splits, int w)

{

field[Lines][Splits]=w;

}

int Getmatrix (int Lines, int Splits)

{

return field[Lines][Splits];

}

};
Jul 22 '05 #1
3 1453
Huibuh wrote:
In one of my header-files I have a class named "matrix" with the function to
construct a matrix. It works properly but at the time of destruction of the
class the program stops. What have I done wrong? Thanks in advance Dieter
[...]


You didn't post any code that shows how you use your matrix. So, I am
guessing here, but most likely you didn't follow the "Rule of Three".
Read about the Rule of Three in the FAQ or in the newsgroup archives
(http://groups.google.com)

V
Jul 22 '05 #2

"Huibuh" <no*****@t-online.de> wrote in message
news:cl*************@news.t-online.com...
In one of my header-files I have a class named "matrix" with the function
to
construct a matrix. It works properly but at the time of destruction of
the
class the program stops. What have I done wrong? Thanks in advance Dieter


You've failed to define either a copy constructor or an assignment operator
when for your class they are desperately needed. Look these up in your
favourite C++ book.

john
Jul 22 '05 #3
"Huibuh" <no*****@t-online.de> wrote:
In one of my header-files I have a class named "matrix" with the function to
construct a matrix. It works properly but at the time of destruction of the
class the program stops. What have I done wrong? Thanks in advance Dieter
In your destructor you have the line:
// delete next;
This line (if it were not commented out) is a problem
because you never assign 'next' in your constructor.
(I think you wanted next = NULL there).

In fact this class is badly designed because you are mixing
the matrix with the implementation of a matrix container.
If you ever change your container requirements (eg. if you
want reverse linking) then you have to change the matrix
class. Instead you should have the matrix and the container
separate.

You could avoid all your problems by using standard containers
and memory management:

class matrix
{
std::vector< std::vector<int> > field;
etc.

and then use std::list<matrix> when you want a list.

};

matrix::matrix(int x, int y)

{

int i, j;

xDim=x;

yDim=y;

field = new int* [xDim];

for(i=0; i<xDim; i++)

field[i] = new int [yDim];

for(i=0; i<xDim; i++)

for(j=0; j<yDim; j++)

field[i][j]=INT_MAX;

}

void Setnext (matrix* ne) {next=ne;}

matrix* Getnext () {return next;}

void Setmatrix (int Lines, int Splits, int w)

{

field[Lines][Splits]=w;

}

int Getmatrix (int Lines, int Splits)

{

return field[Lines][Splits];

}

};

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
3
by: A_Republican | last post by:
I am interested in writing my own secure file deletion program. I want to be able to read and write to my hard drive directly. My application will seach my hard drive for all locations marked for...
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
2
by: DarrenWeber | last post by:
Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
18
by: Hypnotik | last post by:
Hello everyone. I'm writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc. When I run the program I receive "Constructor", which I...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.