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
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