help with this peice of code

Thread Starter

haditya

Joined Jan 19, 2004
220
the problem i am having is the foll:-
1. i have a class matrix--obviously for operations on matrices..consisting of two int to store row and columns and an int** to dynamically build the matrix as a 2-D array.
2. i hav initialized (built up the objects m1,m2 m3) using constuctors and dynamic memory allocation.
3. i want to return an object of class matrix after adding m1 and m2 and assign it to m3.

the problem i am facing is that : -
1. in the function add() there arises the need to create a temporary object of class matrix (m) and assign the result of addition in the function to members of m.
2. the object m is also built by dynamic memory allocation.
3. hence when i return m...the destructor gets called which de-allocates the memory of m and hence the result doesnt get assigned to m3.

i need to find a way to over-ride the destructor.. and i hav the foll idea but i dont know how to implement it:-

build matrix m statically and not dynamically...i want to know how do i setup an array with a double pointer (int**) without using new/delete operators. this way the destructor does not deallocate the memory.


any onther idea to do this will be very much appriciated..

thanks a lot
aditya

PS:-all the functions havnot yet been written...hence they are put as comments//.....kindly ignore that..
several display() calls are used for testing contents of the matrices at various stages
 

Firestorm

Joined Jan 24, 2005
353
hmm...will c what i can find(not that gr8 at programming). Heres a thought though. Since this is programming go to www.cprogramming.com
you will find many tutorials there along with a message board. Might find more programming oriented people there.
thx l8er

-fire
 

nanobyte

Joined May 26, 2004
120
Another good site to go to is www.cpp-home.com. They have excellent forums. I suggest you post your problem there in either the For Beginners forum or the General Programming forum. You will have to register for the forums first before you can post in them.
 
Top