![]() |
|
#1
|
|||
|
|||
debugging multi-dimensional vector/ matrix classHi to all
I am trying to make a multi-dimensional vector/ matrix class: An object on the nth order is composed of (n-1)th order objects. The 0 order object is a float. You might call it a "tensor" class, to be mathematically accurate. Anyway, as far as I have been able to ascertain from various debugging sessions, I have managed to get the collapsible "n-1" order structure right: a constructor for an nth order object of size m calls constructors for (n-1)th order objects m times, until eventually the 0 order objects are created. But somehow the object that has been initialised correctly by put(int) (I have verified this much) gets lost when exiting get(int), see comments in the code. I get nonsense as output. Can anyone help find the bug? This is way past standard tutorial/ troubleshooting material and I am beginning to get frustrated. Many thanks in advance! The class' basic functionality is as follows: CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
Re: debugging multi-dimensional vector/ matrix classYour get() method returns a matrix by-value.
CPP / C++ / C Code:
So, let's look at your copy constructor... CPP / C++ / C Code:
You get nonsense output because the "copied" submatrix contains an uninitialized pointer, and when you dereference it you get garbage. You may want to return a (possibly const) reference to your submatrix, rather than a temporary copy. In any case, you definitely want to implement your copy ctor (and your default ctor as well). Matthew __________________
I was born not knowing and have only had a little time to change that here and there. -- Richard P. Feynman Boris Podolsky: James! How's the rat business? James Moreland: Well, actually it's mostly students I'm experimenting on now. Kurt Gödel: My God, the mazes must be enormous. |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic allocation of multi dimensional array | pointer | C Programming Language | 7 | 13-May-2005 23:50 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | C++ Forum | 2 | 19-Dec-2004 06:06 |
| Help! Some basal questions about MFC | xutingnjupt | MS Visual C++ / MFC Forum | 1 | 05-Dec-2004 03:38 |
| hashing help | saiz66 | C++ Forum | 1 | 06-Jul-2004 06:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The